/*****************************************************************************
*  Copyright Statement:
*  --------------------
*  This software is protected by Copyright and the information contained
*  herein is confidential. The software may not be copied and the information
*  contained herein may not be used or disclosed except with the written
*  permission of MediaTek Inc. (C) 2005
*
*  BY OPENING THIS FILE, BUYER HEREBY UNEQUIVOCALLY ACKNOWLEDGES AND AGREES
*  THAT THE SOFTWARE/FIRMWARE AND ITS DOCUMENTATIONS ("MEDIATEK SOFTWARE")
*  RECEIVED FROM MEDIATEK AND/OR ITS REPRESENTATIVES ARE PROVIDED TO BUYER ON
*  AN "AS-IS" BASIS ONLY. MEDIATEK EXPRESSLY DISCLAIMS ANY AND ALL WARRANTIES,
*  EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED WARRANTIES OF
*  MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE OR NONINFRINGEMENT.
*  NEITHER DOES MEDIATEK PROVIDE ANY WARRANTY WHATSOEVER WITH RESPECT TO THE
*  SOFTWARE OF ANY THIRD PARTY WHICH MAY BE USED BY, INCORPORATED IN, OR
*  SUPPLIED WITH THE MEDIATEK SOFTWARE, AND BUYER AGREES TO LOOK ONLY TO SUCH
*  THIRD PARTY FOR ANY WARRANTY CLAIM RELATING THERETO. MEDIATEK SHALL ALSO
*  NOT BE RESPONSIBLE FOR ANY MEDIATEK SOFTWARE RELEASES MADE TO BUYER'S
*  SPECIFICATION OR TO CONFORM TO A PARTICULAR STANDARD OR OPEN FORUM.
*
*  BUYER'S SOLE AND EXCLUSIVE REMEDY AND MEDIATEK'S ENTIRE AND CUMULATIVE
*  LIABILITY WITH RESPECT TO THE MEDIATEK SOFTWARE RELEASED HEREUNDER WILL BE,
*  AT MEDIATEK'S OPTION, TO REVISE OR REPLACE THE MEDIATEK SOFTWARE AT ISSUE,
*  OR REFUND ANY SOFTWARE LICENSE FEES OR SERVICE CHARGE PAID BY BUYER TO
*  MEDIATEK FOR SUCH MEDIATEK SOFTWARE AT ISSUE. 
*
*  THE TRANSACTION CONTEMPLATED HEREUNDER SHALL BE CONSTRUED IN ACCORDANCE
*  WITH THE LAWS OF THE STATE OF CALIFORNIA, USA, EXCLUDING ITS CONFLICT OF
*  LAWS PRINCIPLES.  ANY DISPUTES, CONTROVERSIES OR CLAIMS ARISING THEREOF AND
*  RELATED THERETO SHALL BE SETTLED BY ARBITRATION IN SAN FRANCISCO, CA, UNDER
*  THE RULES OF THE INTERNATIONAL CHAMBER OF COMMERCE (ICC).
*
*****************************************************************************/

/*******************************************************************************
 * Filename:
 * ---------
 *  PhoneBookList.c
 *
 * Project:
 * --------
 *  MAUI
 *
 * Description:
 * ------------
 *  This file is to provide phonebook list UI
 *
 * Author:
 * -------
 * -------
 *
 *==============================================================================
 *             HISTORY
 * Below this line, this part is controlled by PVCS VM. DO NOT MODIFY!! 
 *------------------------------------------------------------------------------
 * removed!
 *
 * removed!
 * removed!
 * removed!
 *
 * removed!
 * removed!
 * removed!
 *
 * removed!
 * removed!
 * removed!
 *
 * removed!
 * removed!
 * removed!
 *
 * removed!
 * removed!
 * removed!
 *
 * removed!
 * removed!
 * removed!
 *
 * removed!
 * removed!
 * removed!
 *
 * removed!
 * removed!
 * removed!
 *
 * removed!
 * removed!
 * removed!
 *
 * removed!
 * removed!
 * removed!
 *
 * removed!
 * removed!
 * removed!
 *
 * removed!
 * removed!
 * removed!
 *
 * removed!
 * removed!
 * removed!
 *
 * removed!
 * removed!
 * removed!
 *
 * removed!
 * removed!
 * removed!
 *
 * removed!
 * removed!
 * removed!
 *
 * removed!
 * removed!
 * removed!
 *
 * removed!
 * removed!
 * removed!
 *
 * removed!
 * removed!
 * removed!
 *
 * removed!
 * removed!
 * removed!
 *
 * removed!
 * removed!
 * removed!
 *
 * removed!
 * removed!
 * removed!
 *
 * removed!
 * removed!
 * removed!
 *
 * removed!
 * removed!
 * removed!
 *
 * removed!
 * removed!
 * removed!
 *
 * removed!
 * removed!
 * removed!
 *
 * removed!
 * removed!
 * removed!
 *
 * removed!
 * removed!
 * removed!
 *
 * removed!
 * removed!
 * removed!
 *
 * removed!
 * removed!
 * removed!
 *
 * removed!
 * removed!
 * removed!
 *
 * removed!
 * removed!
 * removed!
 * removed!
 *
 *------------------------------------------------------------------------------
 * Upper this line, this part is controlled by PVCS VM. DO NOT MODIFY!! 
 *==============================================================================
 *******************************************************************************/
#include "MMI_include.h"
#include "FileMgrSrvGProt.h"
#include "MMIDataType.h"

#include "CommonScreens.h"

#include "PhoneBookGprot.h"
#include "PhoneBookProt.h"
#include "PhoneBookResDef.h"
#include "PhoneBookTypes.h"
#include "PhoneBookCore.h"
#include "PhbCuiGprot.h"
#include "PhbSrvGprot.h"
#include "MenuCuiGprot.h"
#include "mmi_frm_scenario_gprot.h"

#include "SimDetectionGprot.h"

#include "UCMGprot.h"
#include "UcmSrvGprot.h"

#include "IdleAppDef.h"                     /* for g_idle_context */

#include "SmsSrvGprot.h"

#ifdef __MMI_PHB_SEND_MSG__
#ifdef __MMI_UNIFIED_COMPOSER__
#include "UMGprot.h"
#include "UcAppGprot.h"
#endif /* __MMI_UNIFIED_COMPOSER__ */

#include "SmsGuiInterfaceProt.h"
#include "MessagesMiscell.h"                /* for IsMessagesReEntering */
#include "MessagesResourceData.h"           /* for STR_SMS_MSG_NOT_READY_YET */
#include "SmsSrvGprot.h"
#include "SmsAppGprot.h"
#endif /* __MMI_PHB_SEND_MSG__ */

#ifdef __MMI_MMS__
#include "Mmsadp.h"
#include "mms_adp_struct.h"
#endif /* __MMI_MMS__ */

#include "ProfileGprots.h"

#ifdef __MMI_DUAL_SIM_MASTER__
#include "MTPNP_AD_resdef.h"
#include "MTPNP_PFAL_CC.h"
#endif	/* __MMI_DUAL_SIM_MASTER__ */

#include "simctrlsrvgprot.h"
#include "mmi_rp_app_mainmenu_def.h"
#include "ProfilesSrvGprot.h"
#if defined(__MMI_VCARD__) && defined(__MMI_OPP_SUPPORT__)
#include "BTMMIScrGprots.h"
#endif

/*----------------------------------------------------------------*/
/* Static Variables                                               */
/*----------------------------------------------------------------*/
#if defined(__MMI_PHB_QUICK_SEARCH__)
static U8 g_phb_quick_search_enter;
#endif

static U16 g_mmi_phb_message;
static U16 g_mmi_phb_max_op_finish_count;
static U16 g_mmi_phb_max_op_total_count;
static U16 g_phb_highlight_alpha;

static U16 g_mmi_phb_temp_buffer[100];

static MMI_ID g_mmi_mark_several_menu_id;

/*----------------------------------------------------------------*/
/* Global Variables                                               */
/*----------------------------------------------------------------*/

/**
 * For phb list
 */
mmi_phb_list_cntx_struct *g_mmi_phb_list_p;
mmi_phb_choose_field_struct g_mmi_phb_choose_field;
mmi_phb_contact_info_struct g_mmi_phb_field_data;

#if defined(__MMI_PHB_MULTI_OPERATION__)
MenucuiPtr g_mmi_phb_mark_several_build_op_func;
FunctionPtr g_mmi_phb_mark_several_entry_func;
#endif

extern const U8 phb_edit_field_optional[];
extern pBOOL mmi_bootup_get_active_flight_mode(void);

extern mmi_phb_confirm_user_data_struct g_mmi_phb_confirm_user_data;


/*----------------------------------------------------------------*/
/* static function                                                */
/*----------------------------------------------------------------*/
#ifndef __MMI_PHB_QUICK_SEARCH__
static void mmi_phb_list_entry_main(void);
#else
static void mmi_phb_entry_quick_search_list(void);
#endif

#ifdef __MMI_PHB_TWO_LINE_MENUITEM_DISPLAY__
static void mmi_phb_two_line_send_key_handler(void);
#endif

#if defined(__MMI_PHB_MULTI_OPERATION__) || defined(__MMI_PHB_GENERIC_MULTI_SELECT__)
static U8 mmi_phb_bitmask_get_state(U8* bit_mask, U16 store_index);
#endif

#define MMI_PHB_MAIN_LIST
#ifdef __MMI_FTE_SUPPORT__
/*****************************************************************************
 * FUNCTION
 *  mmi_phb_fte_contact_list_callback
 * DESCRIPTION
 *  fte contact main list toolbar callback
 * PARAMETERS
 *  void
 * RETURNS
 *  void
 *****************************************************************************/
static void mmi_phb_fte_contact_list_callback(S32 index)
{
    /*----------------------------------------------------------------*/
    /* Local Variables                                                */
    /*----------------------------------------------------------------*/

    /*----------------------------------------------------------------*/
    /* Code Body                                                      */
    /*----------------------------------------------------------------*/
    if (index == 0)
    {
        mmi_phb_op_action_cntx_struct op_cntx;
        
        mmi_phb_op_cntx_init(&op_cntx);
        op_cntx.store_index = g_mmi_phb_list_p->store_index;
        op_cntx.op_action = MMI_PHB_OP_CALL;
        
        mmi_phb_op_start(&op_cntx, GRP_ID_PHB_MAIN);
    }
    else if (index == 1)
    {
        mmi_phb_op_action_cntx_struct op_cntx;
        
        mmi_phb_op_cntx_init(&op_cntx);
        op_cntx.store_index = g_mmi_phb_list_p->store_index;

    #ifdef __MMI_PHB_SEND_MSG__
    #ifdef __MMI_UNIFIED_COMPOSER__
        op_cntx.op_action = MMI_PHB_OP_MSG;
        mmi_phb_op_start(&op_cntx, GRP_ID_PHB_MAIN);
    #else /* __MMI_UNIFIED_COMPOSER__ */
        op_cntx.op_action = MMI_PHB_OP_SMS;
        mmi_phb_op_start(&op_cntx, GRP_ID_PHB_MAIN);
    #endif /* __MMI_UNIFIED_COMPOSER__ */
    #endif /* __MMI_PHB_SEND_MSG__ */
    }
    else if (index == 2)
    {
        mmi_phb_op_edit_pre_entry_ext(GRP_ID_PHB_MAIN);
    }
}


/*****************************************************************************
 * FUNCTION
 *  mmi_phb_fte_contact_list_update
 * DESCRIPTION
 *  fte contact main list toolbar update callback
 * PARAMETERS
 *  void
 * RETURNS
 *  void
 *****************************************************************************/
static void mmi_phb_fte_contact_list_update(S32 index, MMI_BOOL set)
{
    /*----------------------------------------------------------------*/
    /* Local Variables                                                */
    /*----------------------------------------------------------------*/
#ifdef __MMI_DUAL_SIM_MASTER__
    E_MTPNP_AD_SIMCARD_USABLE_SIDE state = MTPNP_AD_Get_UsableSide();
#endif /* __MMI_DUAL_SIM_MASTER__ */

    /*----------------------------------------------------------------*/
    /* Code Body                                                      */
    /*----------------------------------------------------------------*/
    if (set)
    {
        wgui_icon_bar_set_item_enable_state(0, MMI_TRUE);
        wgui_icon_bar_set_item_enable_state(1, MMI_TRUE);
        wgui_icon_bar_set_item_enable_state(2, MMI_TRUE);
    }
    else
    {
        wgui_icon_bar_set_item_enable_state(0, MMI_FALSE);
        wgui_icon_bar_set_item_enable_state(1, MMI_FALSE);
        wgui_icon_bar_set_item_enable_state(2, MMI_FALSE);
    }

#ifndef __MMI_PHB_SEND_MSG__
    wgui_icon_bar_set_item_enable_state(1, MMI_FALSE);
#endif

#ifndef __MMI_DUAL_SIM_MASTER__
    if (srv_sim_ctrl_is_available(MMI_SIM1))
    {
        if (mmi_bootup_get_active_flight_mode() == 1)
        {
        #if defined(__MMI_PHB_DIAL_FROM_PHB__)
            wgui_icon_bar_set_item_enable_state(0, MMI_FALSE);
        #endif
        }
    }
    else
    {
    #if defined(__MMI_PHB_DIAL_FROM_PHB__)
        wgui_icon_bar_set_item_enable_state(0, MMI_FALSE);
    #endif 
    }
#else /* __MMI_DUAL_SIM_MASTER__ */
    if (state!= MTPNP_AD_DUALSIM_USABLE && state != MTPNP_AD_SIMCARD1_USABLE && state != MTPNP_AD_SIMCARD2_USABLE)
    {
    #if defined(__MMI_PHB_DIAL_FROM_PHB__)
        wgui_icon_bar_set_item_enable_state(0, MMI_FALSE);
    #endif
    }
#endif /* __MMI_DUAL_SIM_MASTER__ */
    
#ifdef __MMI_PHB_SEND_MSG__
#ifdef __MMI_UNIFIED_COMPOSER__
    if (srv_sms_is_hide_send_sms_menu_item() == TRUE && !mms_is_ready())
    {
        wgui_icon_bar_set_item_enable_state(1, MMI_FALSE);
    }
#else /* __MMI_UNIFIED_COMPOSER__ */
    if (srv_sms_is_hide_send_sms_menu_item() == TRUE)
    {
        wgui_icon_bar_set_item_enable_state(1, MMI_FALSE);
    }
#endif /* __MMI_UNIFIED_COMPOSER__ */
#endif /* __MMI_PHB_SEND_MSG__ */
    
    if (mmi_bootup_get_active_flight_mode() == 1)
    {
        wgui_icon_bar_set_item_enable_state(0, MMI_FALSE);
    }
    
    wgui_icon_bar_update();
}


/*****************************************************************************
 * FUNCTION
 *  mmi_phb_fte_contact_list_tap_callback
 * DESCRIPTION
 *  fte contact main list tap callback
 * PARAMETERS
 *  void
 * RETURNS
 *  void
 *****************************************************************************/
static void mmi_phb_fte_contact_list_tap_callback(mmi_tap_type_enum tap_type, S32 index)
{
    /*----------------------------------------------------------------*/
    /* Local Variables                                                */
    /*----------------------------------------------------------------*/

    /*----------------------------------------------------------------*/
    /* Code Body                                                      */
    /*----------------------------------------------------------------*/
    if (tap_type == ENUM_TAP_ON_HIGHLIGHTED_ITEM)
    {
        if (g_mmi_phb_list_p->store_index == 0xffff)
        {
            mmi_phb_op_add_new_entry_ext(GRP_ID_PHB_MAIN);
        }
        else
        {
            mmi_phb_op_view_pre_entry_ext(GRP_ID_PHB_MAIN);
        }
        return;
    }
    else
    {
        return;
    }
}
#endif /* __MMI_FTE_SUPPORT__ */



void mmi_phb_entry_main_menu(void)
{
    /*----------------------------------------------------------------*/
    /* Local Variables                                                */
    /*----------------------------------------------------------------*/

    /*----------------------------------------------------------------*/
    /* Code Body                                                      */
    /*----------------------------------------------------------------*/

    mmi_phb_launch();
}

/*****************************************************************************
 * FUNCTION
 *  mmi_phb_exit_main_menu
 * DESCRIPTION
 *  Exit function for mmi_phb_entry_main_menu()
 * PARAMETERS
 *  void
 * RETURNS
 *  void
 *****************************************************************************/
void mmi_phb_launch_exit(void)
{
    /*----------------------------------------------------------------*/
    /* Local Variables                                                */
    /*----------------------------------------------------------------*/

    /*----------------------------------------------------------------*/
    /* Code Body                                                      */
    /*----------------------------------------------------------------*/
#if defined(__MMI_INTELLIGENT_CALL_ALERT__)
    mmi_phb_speak_name_end();
#endif /* defined(__MMI_INTELLIGENT_CALL_ALERT__) */

    StopTimer(KEYPAD_LOCK_TIMER);

#ifdef __MMI_WGUI_MINI_TAB_BAR__
    wgui_disable_mini_tab_bar();
#endif
}


/*****************************************************************************
 * FUNCTION
 *  mmi_phb_launch_entry
 * DESCRIPTION
 *  Shows the Phonebook main menu
 * PARAMETERS
 *  void
 * RETURNS
 *  void
 *****************************************************************************/
void mmi_phb_launch_entry(void)
{
    /*----------------------------------------------------------------*/
    /* Local Variables                                                */
    /*----------------------------------------------------------------*/
#if defined(__MMI_PHB_UI_IN_TABS__)
    mmi_frm_tab_struct tab_pages_info_array[MMI_PHB_MAIN_SCREEN_TAB_COUNT];
#endif

    /*----------------------------------------------------------------*/
    /* Code Body                                                      */
    /*----------------------------------------------------------------*/
    if (!srv_phb_startup_is_phb_ready())
    {
        mmi_frm_node_struct *new_node_info = (mmi_frm_node_struct*) srv_phb_mem_malloc(sizeof(mmi_frm_node_struct), SRV_PHB_MEMORY_TYPE_ADM);
        new_node_info->id = GRP_ID_PHB_MAIN;
        new_node_info->entry_proc = (mmi_proc_func) mmi_phb_launch_entry;
        new_node_info->user_data = NULL;
        mmi_phb_entry_main_processing(new_node_info);

        return;
    }
    
    if (!mmi_phb_check_ready(MMI_TRUE))
    {
        return;
    }

#ifdef __MMI_WGUI_MINI_TAB_BAR__
    if (srv_sim_ctrl_is_available(MMI_SIM1)    
    #if defined(__MMI_DUAL_SIM_MASTER__)
        || srv_sim_ctrl_is_available(MMI_SIM2)
    #endif /* __MMI_DUAL_SIM_MASTER__ */
        )
    {
        wgui_enable_mini_tab_bar(MAIN_MENU_PHONEBOOK_MENUID);
    }
    else
    {
        wgui_enable_mini_tab_bar(MAIN_MENU_PHONEBOOK_NO_SIM_MENUID);
    }
#endif /* __MMI_WGUI_MINI_TAB_BAR__ */ 

/* Tab style */
#if defined(__MMI_PHB_UI_IN_TABS__)

#if defined(__MMI_PHB_QUICK_SEARCH__)
    tab_pages_info_array[0].screen_id = SCR_ID_PHB_QUICK_SEARCH_LIST;
    tab_pages_info_array[0].tab_entry_func = mmi_phb_entry_quick_search_list_tab;
#else
    tab_pages_info_array[0].screen_id = SCR_PBOOK_LIST;
    tab_pages_info_array[0].tab_entry_func = mmi_phb_list_entry_main;
#endif
    tab_pages_info_array[0].tab_icon = (U8*)GetImage(IMG_ID_PHB_TAB_LIST);
    tab_pages_info_array[0].tab_string = NULL;
    
    tab_pages_info_array[1].screen_id = SCR_CALLER_GROUPS;
    tab_pages_info_array[1].tab_entry_func = mmi_phb_entry_group_list_tab;
    tab_pages_info_array[1].tab_icon = (U8*)GetImage(IMG_ID_PHB_TAB_GROUP);
    tab_pages_info_array[1].tab_string = NULL;

    mmi_frm_scrn_tab_enter(
        GRP_ID_PHB_MAIN,
        SCR_PBOOK_MAIN_MENU,
        mmi_phb_launch_exit,
        mmi_phb_launch_entry,
        tab_pages_info_array,
        MMI_PHB_MAIN_SCREEN_TAB_COUNT,
        mmi_frm_scrn_tab_get_active_page_index());

/* quick search list */    
#elif defined(__MMI_PHB_QUICK_SEARCH__)
    mmi_phb_entry_quick_search_list();
/* normal list */
#else
    mmi_phb_list_entry_main();
#endif
}


static U16 mmi_phb_calc_list_index(
            mmi_phb_refresh_struct *refresh_data,
            U8 list_type,
            U16 old_list_index,
            U16 *store_index_array,
            U8* bit_mask,
            U16 contact_count)
{
    /*----------------------------------------------------------------*/
    /* Local Variables                                                */
    /*----------------------------------------------------------------*/
    U16 list_index = old_list_index;
    
    /*----------------------------------------------------------------*/
    /* Code Body                                                      */
    /*----------------------------------------------------------------*/
    switch (refresh_data->refresh_type)
    {
        case MMI_PHB_OP_ADD:
        case MMI_PHB_OP_EDIT:
        case MMI_PHB_OP_MOVE:
        case MMI_PHB_OP_COPY:
            for (list_index = 0; list_index < contact_count; list_index++)
            {
                if (store_index_array[list_index] == refresh_data->new_store_index)
                {
                    break;
                }
            }

            if (refresh_data->sg_id == GRP_ID_PHB_MAIN)
            {
                if (list_index >= contact_count)
                {
                    list_index = old_list_index;
                }
            }
            else
            {
                if (list_index <= old_list_index)
                {
                    list_index = old_list_index + 1;
                }
                else
                {
                    list_index = old_list_index;
                }
            }
            break;
            
        case MMI_PHB_OP_DELETE:
            list_index = old_list_index;
            break;

    #if defined(__MMI_PHB_MULTI_OPERATION__) || defined(__MMI_PHB_GENERIC_MULTI_SELECT__)
        case MMI_PHB_OP_COPY_ALL:
        case MMI_PHB_OP_DELETE_ALL:
        case MMI_PHB_OP_MOVE_ALL:
        case MMI_PHB_OP_MULTI_COPY:
        case MMI_PHB_OP_MULTI_DELETE:
        case MMI_PHB_OP_MULTI_MOVE:
        {
            if (list_type == MMI_PHB_LIST_TYPE_MULTI_SELECT && bit_mask)
            {
                for (list_index = 0; list_index < contact_count; list_index++)
                {
                    if (mmi_phb_bitmask_get_state(bit_mask, store_index_array[list_index]))
                    {
                        break;
                    }
                }
            }
            else if (list_type == MMI_PHB_LIST_TYPE_SINGLE_SELECT)
            {
                list_index = 0;
            }
            break;
        }
    #endif
    
        default:
            break;
    }
    
    if (list_index >= contact_count)
    {
        list_index--;
    }

    return list_index;
}


#ifndef __MMI_PHB_QUICK_SEARCH__
/*****************************************************************************
 * FUNCTION
 *  mmi_phb_list_entry_main_highlight_hdlr
 * DESCRIPTION
 *  
 * PARAMETERS
 *  item_index      [IN]        
 * RETURNS
 *  void
 *****************************************************************************/
static void mmi_phb_list_entry_main_highlight_hdlr(S32 item_index)
{
    /*----------------------------------------------------------------*/
    /* Local Variables                                                */
    /*----------------------------------------------------------------*/

    /*----------------------------------------------------------------*/
    /* Code Body                                                      */
    /*----------------------------------------------------------------*/
#if defined(__MMI_INTELLIGENT_CALL_ALERT__)
    mmi_phb_speak_name_end();
#endif /* defined(__MMI_INTELLIGENT_CALL_ALERT__) */ 

    if (item_index == 0)
    {
        g_mmi_phb_list_p->list_index = 0;
        g_mmi_phb_list_p->store_index = 0xffff;
        
        ChangeCenterSoftkey(0, IMG_ID_PHB_CSK_ADD);
        SetCenterSoftkeyFunction(mmi_phb_op_add_new_entry, KEY_EVENT_UP);
    
        SetKeyHandler(NULL, KEY_SEND, KEY_EVENT_UP);
        
    #if defined(__IP_NUMBER__) && defined(__MMI_IP_KEY__)
/* under construction !*/
    #endif /* defined(__IP_NUMBER__) && defined(__MMI_IP_KEY__) */ 

    #ifdef __MMI_FTE_SUPPORT__
        mmi_phb_fte_contact_list_update(0,MMI_FALSE);
    #endif
        return;
    }
    else
    {
    #ifdef __MMI_PHB_DEFAULT_NUMBER__
        SetKeyHandler(mmi_phb_dial_default_number_and_start_browser, KEY_SEND, KEY_EVENT_UP);
    #else
        SetKeyHandler(mmi_phb_dial_normal_call, KEY_SEND, KEY_EVENT_UP);
    #endif
    
    #if defined(__IP_NUMBER__) && defined(__MMI_IP_KEY__)   /* For IP Dial Key */
/* under construction !*/
    #endif /* defined(__IP_NUMBER__) && defined(__MMI_IP_KEY__) */ 

        item_index--;
    }

    ChangeCenterSoftkey(0, IMG_GLOBAL_COMMON_CSK);
    SetCenterSoftkeyFunction(mmi_phb_op_view_pre_entry, KEY_EVENT_UP);

    g_mmi_phb_list_p->list_index = item_index;
    g_mmi_phb_list_p->store_index = g_mmi_phb_list_p->contact_array[item_index];

#ifdef __MMI_FTE_SUPPORT__
        mmi_phb_fte_contact_list_update(0,MMI_TRUE);
    #endif
    
#if defined(__MMI_INTELLIGENT_CALL_ALERT__)
    mmi_phb_speak_name_start();
#endif /* defined(__MMI_INTELLIGENT_CALL_ALERT__) */ 
}


static pBOOL mmi_phb_list_entry_main_get_item(S32 item_index, UI_string_type str_buff, PU8 *img_buff_p, U8 str_img_mask)
{
    /*----------------------------------------------------------------*/
    /* Local Variables                                                */
    /*----------------------------------------------------------------*/

    /*----------------------------------------------------------------*/
    /* Code Body                                                      */
    /*----------------------------------------------------------------*/
    if (item_index == 0)
    {
        mmi_ucs2cpy((S8*) str_buff, GetString(STR_ID_PHB_ADD_NEW_CONTACT));
        *img_buff_p = NULL;

        return TRUE;
    }
    else
    {
        item_index--;
    }
    
    mmi_phb_list_get_item(item_index, str_buff, img_buff_p, str_img_mask);

    return TRUE;
}


static S32 mmi_phb_list_entry_main_get_hint(S32 item_index, UI_string_type *hint_array)
{
    /*----------------------------------------------------------------*/
    /* Local Variables                                                */
    /*----------------------------------------------------------------*/

    /*----------------------------------------------------------------*/
    /* Code Body                                                      */
    /*----------------------------------------------------------------*/
    if (item_index == 0)
    {
        return 0;
    }
    else
    {
        item_index--;
    }
    
    return mmi_phb_list_get_hint_ext(item_index, hint_array);
}


static MMI_BOOL mmi_phb_list_entry_main_seperate_line(S32 index, U32* flag, U32* flag_ex)
{
    /*----------------------------------------------------------------*/
    /* Local Variables                                                */
    /*----------------------------------------------------------------*/

    /*----------------------------------------------------------------*/
    /* Code Body                                                      */
    /*----------------------------------------------------------------*/
    if (index == 0)
    {
        *flag_ex |= UI_MENUITEM_EXT_SHOW_DOWN_SEPARATORLINE;
        return MMI_TRUE;
    }

    return MMI_FALSE;
}


static void mmi_phb_list_entry_main(void)
{
    /*----------------------------------------------------------------*/
    /* Local Variables                                                */
    /*----------------------------------------------------------------*/
    U8 *gui_buffer;
    U16 contact_count;
    srv_phb_filter_struct * filter;
    U32 handle;
    mmi_phb_refresh_struct *refresh_data;
#ifdef __MMI_FTE_SUPPORT__
    S32 item_count = 3;
    PU8 item_icon[3] = {NULL, NULL, NULL};
    PU8 item_disable_icon[3] = {NULL, NULL, NULL};
    PU8 string[3] = {NULL, NULL, NULL};
#endif /* __MMI_FTE_SUPPORT__ */

    /*----------------------------------------------------------------*/
    /* Code Body                                                      */
    /*----------------------------------------------------------------*/        
    if (!mmi_frm_scrn_enter(
            GRP_ID_PHB_MAIN,
            SCR_PBOOK_LIST,
            mmi_phb_launch_exit,
        #if !defined(__MMI_PHB_UI_IN_TABS__)
            mmi_phb_launch_entry,
            MMI_FRM_FULL_SCRN
        #else
            mmi_phb_list_entry_main,
            MMI_FRM_TAB_PAGE
        #endif
            ))
    {
        return;
    }

    gui_buffer = mmi_frm_scrn_get_active_gui_buf();

    /* refresh prefer storage */
    if (g_mmi_phb_list_p->storage != mmi_phb_get_preferred_storage() ||
        g_mmi_phb_list_p->display_type != srv_phb_get_name_display_type())
    {
        g_mmi_phb_list_p->storage = (U8) mmi_phb_get_preferred_storage();
        g_mmi_phb_list_p->display_type = (U8) srv_phb_get_name_display_type();
        gui_buffer = NULL;
    }

    RegisterHighlightHandler(mmi_phb_list_entry_main_highlight_hdlr);
    
    filter = mmi_phb_list_build_filter(
                 g_mmi_phb_list_p->storage,
                 g_mmi_phb_list_p->filter,
                 NULL,
                 NULL,
                 0);
    
    contact_count = (U16) srv_phb_oplib_build_contact_list(filter, g_mmi_phb_list_p->contact_array, MMI_PHB_ENTRIES);
    g_mmi_phb_list_p->contact_count = contact_count;

    mmi_phb_list_free_filter(filter);

    if (gui_buffer == NULL)
    {
        g_phb_highlight_alpha = 0;
        
        if (contact_count == 0)
        {
            g_mmi_phb_list_p->list_index = 0;        
        }
        else
        {
            g_mmi_phb_list_p->list_index = 1;
        }

        contact_count++;

    }
    else if (!mmi_is_redrawing_bk_screens())
    {
        handle = mmi_phb_cntx_mgr_get_handle_by_sg_id(mmi_phb_cntx_mgr_get_current_sg_id());
        refresh_data = mmi_phb_cntx_mgr_get_refresh_data(handle);

        if (refresh_data != NULL && refresh_data->refresh_type != MMI_PHB_OP_NONE)
        {
            gui_buffer = NULL;

            if (contact_count == 0)
            {
                g_mmi_phb_list_p->list_index = 0;
            }
            else
            {
                g_mmi_phb_list_p->list_index = mmi_phb_calc_list_index(
                                                refresh_data,
                                                MMI_PHB_LIST_TYPE_SINGLE_SELECT,
                                                g_mmi_phb_list_p->list_index,
                                                g_mmi_phb_list_p->contact_array,
                                                NULL,
                                                g_mmi_phb_list_p->contact_count);

                g_mmi_phb_list_p->list_index++;
            }            
            refresh_data->refresh_type = MMI_PHB_OP_NONE;
        }
        contact_count++;
    }
    
    /**
     * Always call build alpha jump function
     */
    srv_phb_oplib_build_alpha_jump_table(g_mmi_phb_list_p->contact_array, g_mmi_phb_list_p->contact_count);

    EnableCenterSoftkey(0, IMG_GLOBAL_COMMON_CSK);

    wgui_fixed_list_register_get_flags_handler(mmi_phb_list_entry_main_seperate_line);

#ifdef __MMI_FTE_SUPPORT__
    item_icon[0] = get_image(IMG_GLOBAL_TOOLBAR_CALL);
    item_icon[1] = get_image(IMG_GLOBAL_TOOLBAR_SEND_MESSAGE);
    item_icon[2] = get_image(IMG_GLOBAL_TOOLBAR_EDIT);
    item_disable_icon[0] = get_image(IMG_GLOBAL_TOOLBAR_CALL_DISABLED);
    item_disable_icon[1] = get_image(IMG_GLOBAL_TOOLBAR_SEND_MESSAGE_DISABLED);
    item_disable_icon[2] = get_image(IMG_GLOBAL_TOOLBAR_EDIT_DISABLED);
    string[0] = (PU8)get_string((STR_GLOBAL_DIAL));
    string[1] = (PU8)get_string((STR_GLOBAL_SEND));
    string[2] = (PU8)get_string((STR_GLOBAL_EDIT));
    wgui_icon_bar_setup(item_count, item_icon, item_disable_icon, string, (GUIIconbarItemCallback)mmi_phb_fte_contact_list_callback);
#endif /* __MMI_FTE_SUPPORT__ */

#if !defined(__MMI_PHB_UI_IN_TABS__)
    ShowCategory284Screen(
        STR_SCR_PBOOK_VIEW_CAPTION,
        IMG_SCR_PBOOK_CAPTION,
        STR_GLOBAL_OPTIONS,
        IMG_GLOBAL_OPTIONS,
        STR_GLOBAL_BACK,
        IMG_GLOBAL_BACK,
        contact_count,
        mmi_phb_list_entry_main_get_item,
        mmi_phb_list_entry_main_get_hint,
        g_mmi_phb_list_p->list_index,
        gui_buffer);
#else
    wgui_cat629_set_text_align_left();

    ShowCategory629Screen(
        STR_SCR_PBOOK_VIEW_CAPTION,
        IMG_SCR_PBOOK_CAPTION,
        STR_GLOBAL_OPTIONS,
        IMG_GLOBAL_OPTIONS,
        STR_GLOBAL_BACK,
        IMG_GLOBAL_BACK,
        contact_count,
        mmi_phb_list_entry_main_get_item,
        mmi_phb_list_entry_main_get_hint,
        g_mmi_phb_list_p->list_index,
        0,
        gui_buffer);
#endif


    /* register multi-tap function for fast jump, for full list only */
#ifdef __MMI_QWERTY_KEYPAD_SUPPORT__
    mmi_frm_set_keypad_mode(KEYPAD_1KEY_QWERTY);
    mmi_frm_set_app_translate_key_handler(mmi_phb_list_alpha_callback_ext);
#else
    wgui_setup_multitap_functions(WGUI_MULTITAP_TYPE_UPPERCASE_ABC, mmi_phb_list_alpha_index, mmi_phb_list_alpha_index_input_callback_ext);
#endif

    SetLeftSoftkeyFunction(mmi_phb_entry_op_option, KEY_EVENT_UP);
    SetRightSoftkeyFunction(mmi_frm_scrn_close_active_id, KEY_EVENT_UP);

#ifdef __MMI_FTE_SUPPORT__
    wgui_register_tap_callback(mmi_phb_fte_contact_list_tap_callback);
#endif /* __MMI_FTE_SUPPORT__ */
}
#endif /* __MMI_PHB_QUICK_SEARCH__ */


#define MMI_PHB_NORMAL_LIST

void mmi_phb_list_entry(void)
{
    /*----------------------------------------------------------------*/
    /* Local Variables                                                */
    /*----------------------------------------------------------------*/
    U16 contact_count;
    srv_phb_filter_struct * filter;
    
    /*----------------------------------------------------------------*/
    /* Code Body                                                      */
    /*----------------------------------------------------------------*/
    if (!srv_phb_startup_is_phb_ready())
    {
        mmi_frm_node_struct *new_node_info = (mmi_frm_node_struct*) srv_phb_mem_malloc(sizeof(mmi_frm_node_struct), SRV_PHB_MEMORY_TYPE_ADM);
        new_node_info->id = GRP_ID_PHB_MAIN;
        new_node_info->entry_proc = (mmi_proc_func) mmi_phb_list_entry;
        new_node_info->user_data = NULL;
        mmi_phb_entry_main_processing(new_node_info);

        return;
    }

    if (!mmi_phb_check_ready(MMI_TRUE))
    {
        return;   
    }
    
#if defined(__MMI_FILE_MANAGER__) && (!defined __MMI_PHB_TWO_LINE_MENUITEM_DISPLAY__)
   // if (UI_device_height == 220 && UI_device_width == 176)
    {
        //mmi_phb_entry_image_list1();
    }
   // else
#endif /* defined(__MMI_FILE_MANAGER__) && (!defined __MMI_PHB_TWO_LINE_MENUITEM_DISPLAY__) */ 
    {
        FunctionPtr send_key_ptr;
    #ifdef __MMI_PHB_TWO_LINE_MENUITEM_DISPLAY__
        send_key_ptr = mmi_phb_two_line_send_key_handler;
    #else /* __MMI_PHB_TWO_LINE_MENUITEM_DISPLAY__ */
    #ifdef __MMI_PHB_DEFAULT_NUMBER__
        send_key_ptr = mmi_phb_dial_default_number_and_start_browser;
    #else
        send_key_ptr = mmi_phb_dial_normal_call;
    #endif
    #endif

        filter = mmi_phb_list_build_filter(
                     (U8) mmi_phb_get_preferred_storage(),
                     g_mmi_phb_list_p->filter,
                     &g_mmi_phb_list_p->group_filter,
                     NULL,
                     0);
        
        contact_count = (U16) srv_phb_oplib_build_contact_list(filter, g_mmi_phb_list_p->contact_array, MMI_PHB_ENTRIES);
        g_mmi_phb_list_p->contact_count = contact_count;
        
        mmi_phb_list_free_filter(filter);

        if (contact_count == 0)
        {
            mmi_popup_display(
                (WCHAR *)GetString(STR_NO_ENTRIES_MESSAGE),
                MMI_EVENT_FAILURE,
                NULL);

            mmi_frm_group_close(GRP_ID_PHB_MAIN);
            return;
        }

        mmi_phb_entry_list(
            mmi_phb_cntx_mgr_get_current_sg_id(),
            contact_count,                          /* Total Entry */
            STR_SCR_PBOOK_VIEW_CAPTION,             /* Title String */
            IMG_SCR_PBOOK_CAPTION,                  /* Title Image */
            STR_GLOBAL_OPTIONS,                     /* LSK */
            IMG_GLOBAL_OPTIONS,                     /* LSK */
            (U16)0,
            IMG_GLOBAL_COMMON_CSK,
            mmi_phb_list_highlight_handler,         /* Highlight Callback */
            mmi_phb_entry_op_option,                /* LSK Callback */
            mmi_phb_op_view_pre_entry,            /* CSK Callback */
            send_key_ptr,                           /* SEND Key Callback */
            mmi_phb_list_get_item,                  /* List Callback */
            mmi_phb_list_get_hint_ext,              /* Hint Callback */
            mmi_phb_list_entry,                     /* Re-Entry Callback */
            MMI_TRUE);                              /* Alpha Index */
    }
}

/*****************************************************************************
 * FUNCTION
 *  mmi_phb_list_pre_entry
 * DESCRIPTION
 *  This function provide call back function before enter phonebook list
 * PARAMETERS
 *  void
 * RETURNS
 *  void
 *****************************************************************************/
void mmi_phb_list_pre_entry(void)
{
    /*----------------------------------------------------------------*/
    /* Local Variables                                                */
    /*----------------------------------------------------------------*/
    U32 handle;
    mmi_phb_list_cntx_struct *main_cntx;
    
    /*----------------------------------------------------------------*/
    /* Code Body                                                      */
    /*----------------------------------------------------------------*/
    if (srv_phb_startup_is_phb_ready())
    {
        if (!mmi_phb_check_ready(MMI_TRUE))
        {
            return;
        }
    }

    /* re-entry phonebook, delete old history */
    mmi_phb_cntx_mgr_clear_history();

    /**
     * create handle
     */
    handle = mmi_phb_cntx_mgr_create_handle(MMI_PHB_SG_MAIN);
    main_cntx = cui_phb_list_select_contact_create_cntx(MMI_PHB_LIST_TYPE_SINGLE_SELECT);

    main_cntx->sg_id = GRP_ID_PHB_MAIN;
    main_cntx->parent_id = GRP_ID_INVALID;
    
    mmi_phb_cntx_mgr_set_data(handle, main_cntx);

    mmi_frm_group_create(
        GRP_ID_ROOT,
        GRP_ID_PHB_MAIN,
        mmi_phb_launch_proc,
        main_cntx);
    mmi_frm_group_enter(GRP_ID_PHB_MAIN, MMI_FRM_NODE_SMART_CLOSE_FLAG);

    mmi_phb_list_entry();    
}

#define MMI_PHB_QUICKSEARCH

#if defined(__MMI_PHB_QUICK_SEARCH__)
/*****************************************************************************
 * FUNCTION
 *  mmi_phb_quick_search_change_input_mode
 * DESCRIPTION
 *  
 * PARAMETERS
 *  void
 * RETURNS
 *  void
 *****************************************************************************/
void mmi_phb_quick_search_change_input_mode(void)
{
    /*----------------------------------------------------------------*/
    /* Local Variables                                                */
    /*----------------------------------------------------------------*/

    /*----------------------------------------------------------------*/
    /* Code Body                                                      */
    /*----------------------------------------------------------------*/
    /**
     * refresh the quicksearch list
     */
    mmi_phb_cntx_mgr_input_method_change();

    /**
     * Call srv api to make cache again
     */
}


/*****************************************************************************
 * FUNCTION
 *  mmi_phb_quick_search_find_entry
 * DESCRIPTION
 *  
 * PARAMETERS
 *  keyword     [?]     
 * RETURNS
 *  
 *****************************************************************************/
S32 mmi_phb_quick_search_find_entry(U8 *keyword)
{
    /*----------------------------------------------------------------*/
    /* Local Variables                                                */
    /*----------------------------------------------------------------*/
    U32 key_length;
    S32 result_count;
    srv_phb_filter_struct * filter;

    /*----------------------------------------------------------------*/
    /* Code Body                                                      */
    /*----------------------------------------------------------------*/
    /* Count the input string length to decide behavior */
    key_length = (U8) mmi_ucs2strlen((S8*) keyword);
    result_count = 0;

    /* add new contact , so result_count++ */
    if (g_phb_quick_search_enter == MMI_PHB_QUICK_SEARCH_MAIN && key_length == 0)
    {
        result_count++;
    }

    /**
     * build searched contact list
     */
    
    filter = mmi_phb_list_build_filter(
                 g_mmi_phb_list_p->storage,
                 g_mmi_phb_list_p->filter,
                 &g_mmi_phb_list_p->group_filter,
                 (U16*)keyword,
                 (U16)mmi_imm_get_curr_input_mode());
    
    g_mmi_phb_list_p->contact_count = (U16) srv_phb_oplib_build_contact_list(filter, g_mmi_phb_list_p->contact_array, MMI_PHB_ENTRIES);
    result_count += g_mmi_phb_list_p->contact_count;

    mmi_phb_list_free_filter(filter);
    
    if (g_phb_quick_search_enter == MMI_PHB_QUICK_SEARCH_MAIN)
    {
        if (result_count == 0)  /* Clear send key when no entry found */
        {
            ClearKeyHandler(KEY_SEND, KEY_EVENT_UP);
        #if defined(__MMI_INTELLIGENT_CALL_ALERT__)
            mmi_phb_speak_name_end();
        #endif /* defined(__MMI_INTELLIGENT_CALL_ALERT__) */ 
        }
        else
        {
        #ifdef __MMI_PHB_DEFAULT_NUMBER__
            SetKeyHandler(mmi_phb_dial_default_number_and_start_browser, KEY_SEND, KEY_EVENT_UP);
        #else
            SetKeyHandler(mmi_phb_dial_normal_call, KEY_SEND, KEY_EVENT_UP);
        #endif     
        }
    }
    else if (g_phb_quick_search_enter == MMI_PHB_QUICK_SEARCH_GENERIC)
    {
        if (result_count == 0)  /* Clear send key when no entry found */
        {
            ClearKeyHandler(KEY_SEND, KEY_EVENT_UP);
        }
    }
    else
    {
        ASSERT(0);
    }

    if (result_count == 0)
    {
        U16 cur_screen = mmi_frm_scrn_get_active_id();
        if (cur_screen == SCR_ID_PHB_GENERIC_MULTI_SELECT
            || cur_screen == SCR_ID_PHB_QUICK_SEARCH_LIST
            || cur_screen == SCR_ID_PHB_MULTI_OP_PHB_LIST
            || cur_screen == SCR_PBOOK_MAIN_MENU
            || cur_screen == SCR_ID_PHB_GENERIC_QUICK_SEARCH_LIST)
        {
            ChangeCenterSoftkey(0, 0);
        }
    }
    else
    {
        U16 cur_screen = mmi_frm_scrn_get_active_id();
        if (cur_screen == SCR_ID_PHB_GENERIC_QUICK_SEARCH_LIST)
        {
            ChangeCenterSoftkey(0, IMG_GLOBAL_COMMON_CSK);
        }
    }

#ifdef __MMI_FTE_SUPPORT__
    if (result_count == 0)
    {
        mmi_phb_fte_contact_list_update(0, MMI_FALSE);
    }
#endif

    return result_count;
}


static S32 mmi_phb_quick_search_find_entry_tab(U8 *keyword)
{
    /*----------------------------------------------------------------*/
    /* Local Variables                                                */
    /*----------------------------------------------------------------*/
    S32 result_count;
    
    /*----------------------------------------------------------------*/
    /* Code Body                                                      */
    /*----------------------------------------------------------------*/
    result_count = mmi_phb_quick_search_find_entry(keyword);

    if (result_count == 0)
    {
        SetKeyHandler(mmi_frm_general_tab_l_arrow_key_hdlr, KEY_LEFT_ARROW, KEY_EVENT_DOWN);
        SetKeyHandler(mmi_frm_general_tab_r_arrow_key_hdlr, KEY_RIGHT_ARROW, KEY_EVENT_DOWN);
    }

    return result_count;
}


/*****************************************************************************
 * FUNCTION
 *  mmi_phb_quick_search_get_index
 * DESCRIPTION
 *  
 * PARAMETERS
 *  item_index      [IN]        
 * RETURNS
 *  void
 *****************************************************************************/
static void mmi_phb_quick_search_get_index(S32 item_index)
{
    /*----------------------------------------------------------------*/
    /* Local Variables                                                */
    /*----------------------------------------------------------------*/

    /*----------------------------------------------------------------*/
    /* Code Body                                                      */
    /*----------------------------------------------------------------*/
#if defined(__MMI_INTELLIGENT_CALL_ALERT__)
    mmi_phb_speak_name_end();
#endif /* defined(__MMI_INTELLIGENT_CALL_ALERT__) */ 

#ifdef __MMI_PHB_DEFAULT_NUMBER__
    SetKeyHandler(mmi_phb_dial_default_number_and_start_browser, KEY_SEND, KEY_EVENT_UP);
#else
    SetKeyHandler(mmi_phb_dial_normal_call, KEY_SEND, KEY_EVENT_UP);
#endif

    if (g_mmi_phb_list_p->qsearch_input_buffer[0] == 0)
    {
        if (item_index == 0)
        {
            g_mmi_phb_list_p->list_index = 0;
            g_mmi_phb_list_p->store_index = 0xffff;
            
            ChangeCenterSoftkey(0, IMG_ID_PHB_CSK_ADD);

            SetKeyHandler(NULL, KEY_SEND, KEY_EVENT_UP);

        #ifdef __MMI_FTE_SUPPORT__
            mmi_phb_fte_contact_list_update(0, MMI_FALSE);
        #endif
            return;
        }
        else
        {
            item_index--;
        }
    }

    ChangeCenterSoftkey(0, IMG_GLOBAL_COMMON_CSK);

    g_mmi_phb_list_p->list_index = item_index;
    g_mmi_phb_list_p->store_index = g_mmi_phb_list_p->contact_array[item_index];
    
#if defined(__MMI_INTELLIGENT_CALL_ALERT__)
    mmi_phb_speak_name_start();
#endif /* defined(__MMI_INTELLIGENT_CALL_ALERT__) */

#ifdef __MMI_FTE_SUPPORT__
    mmi_phb_fte_contact_list_update(item_index, MMI_TRUE);
#endif
}


static void mmi_phb_quick_search_get_index_tab(S32 item_index)
{
    /*----------------------------------------------------------------*/
    /* Local Variables                                                */
    /*----------------------------------------------------------------*/

    /*----------------------------------------------------------------*/
    /* Code Body                                                      */
    /*----------------------------------------------------------------*/

    SetKeyHandler(mmi_frm_general_tab_l_arrow_key_hdlr, KEY_LEFT_ARROW, KEY_EVENT_DOWN);
    SetKeyHandler(mmi_frm_general_tab_r_arrow_key_hdlr, KEY_RIGHT_ARROW, KEY_EVENT_DOWN);

    mmi_phb_quick_search_get_index(item_index);
}


static void mmi_phb_quick_search_center_key_handlr(void)
{
    /*----------------------------------------------------------------*/
    /* Local Variables                                                */
    /*----------------------------------------------------------------*/

    /*----------------------------------------------------------------*/
    /* Code Body                                                      */
    /*----------------------------------------------------------------*/
    if (g_mmi_phb_list_p->store_index == 0xffff)
    {
        mmi_phb_op_add_new_entry_ext(GRP_ID_PHB_MAIN);
    }
    else
    {
        mmi_phb_op_view_pre_entry_ext(GRP_ID_PHB_MAIN);
    }
}


/*****************************************************************************
 * FUNCTION
 *  mmi_phb_quick_search_list_get_item
 * DESCRIPTION
 *  
 * PARAMETERS
 *  item_index          [IN]        
 *  str_buff            [IN]        
 *  img_buff_p          [?]         
 *  str_img_mask        [IN]        
 * RETURNS
 *  
 *****************************************************************************/
static pBOOL mmi_phb_quick_search_list_get_item(S32 item_index, UI_string_type str_buff, PU8 *img_buff_p, U8 str_img_mask)
{
    /*----------------------------------------------------------------*/
    /* Local Variables                                                */
    /*----------------------------------------------------------------*/

    /*----------------------------------------------------------------*/
    /* Code Body                                                      */
    /*----------------------------------------------------------------*/
    if (g_mmi_phb_list_p->qsearch_input_buffer[0] == 0)
    {
        if (item_index == 0)
        {
            mmi_ucs2cpy((S8*) str_buff, GetString(STR_ID_PHB_ADD_NEW_CONTACT));
            *img_buff_p = NULL;
            return TRUE;
        }
        else
        {
            item_index--;
        }
    }
    
    mmi_phb_list_get_item(item_index, str_buff, img_buff_p, str_img_mask);
    
    return TRUE;
}


/*****************************************************************************
 * FUNCTION
 *  mmi_phb_quick_search_list_get_hint
 * DESCRIPTION
 *  
 * PARAMETERS
 *  item_index      [IN]        
 *  hint_array      [?]         
 * RETURNS
 *  
 *****************************************************************************/
static S32 mmi_phb_quick_search_list_get_hint(S32 item_index, UI_string_type *hint_array)
{
    /*----------------------------------------------------------------*/
    /* Local Variables                                                */
    /*----------------------------------------------------------------*/

    /*----------------------------------------------------------------*/
    /* Code Body                                                      */
    /*----------------------------------------------------------------*/
    if (g_mmi_phb_list_p->qsearch_input_buffer[0] == 0)
    {
        if (item_index == 0)
        {
            return 0;
        }
        else
        {
            item_index--;
        }
    }

    return mmi_phb_list_get_hint_ext(item_index, hint_array);
}


static MMI_BOOL mmi_phb_quick_search_list_seperate_line(S32 index, U32* flag, U32* flag_ex)
{
    /*----------------------------------------------------------------*/
    /* Local Variables                                                */
    /*----------------------------------------------------------------*/

    /*----------------------------------------------------------------*/
    /* Code Body                                                      */
    /*----------------------------------------------------------------*/
    if (g_mmi_phb_list_p->qsearch_input_buffer[0] == 0 && index == 0)
    {
        *flag_ex |= UI_MENUITEM_EXT_SHOW_DOWN_SEPARATORLINE;
        return MMI_TRUE;
    }

    return MMI_FALSE;
}


static void mmi_phb_exit_quick_search_list_tab(void)
{
    /*----------------------------------------------------------------*/
    /* Local Variables                                                */
    /*----------------------------------------------------------------*/

    /*----------------------------------------------------------------*/
    /* Code Body                                                      */
    /*----------------------------------------------------------------*/    
    StopTimer(KEYPAD_LOCK_TIMER);

#if defined(__MMI_VRSD_DIAL__)
    StopTimer(VRSD_DIAL_PLAYBACK_TIMER);
#endif 

#if defined(__MMI_INTELLIGENT_CALL_ALERT__)
    mmi_phb_speak_name_end();
#endif /* defined(__MMI_INTELLIGENT_CALL_ALERT__) */
}


/*****************************************************************************
 * FUNCTION
 *  mmi_phb_entry_quick_search_list
 * DESCRIPTION
 *  
 * PARAMETERS
 *  void
 * RETURNS
 *  void
 *****************************************************************************/
void mmi_phb_entry_quick_search_list_tab(void)
{
    /*----------------------------------------------------------------*/
    /* Local Variables                                                */
    /*----------------------------------------------------------------*/
    U8 *gui_buffer;
    U16 contact_count;
    srv_phb_filter_struct * filter;
    U32 handle;
    mmi_phb_refresh_struct *refresh_data;
#ifdef __MMI_FTE_SUPPORT__
    S32 item_count = 3;
    PU8 item_icon[3] = {NULL, NULL, NULL};
    PU8 item_disable_icon[3] = {NULL, NULL, NULL};
    PU8 string[3] = {NULL, NULL, NULL};
#endif /* __MMI_FTE_SUPPORT__ */

    /*----------------------------------------------------------------*/
    /* Code Body                                                      */
    /*----------------------------------------------------------------*/
    if (!mmi_frm_scrn_enter(
            GRP_ID_PHB_MAIN,
            SCR_ID_PHB_QUICK_SEARCH_LIST,
            mmi_phb_exit_quick_search_list_tab,
            mmi_phb_entry_quick_search_list_tab,
            MMI_FRM_TAB_PAGE))
    {
        return;
    }

    g_phb_quick_search_enter = MMI_PHB_QUICK_SEARCH_MAIN;
        
    gui_buffer = mmi_frm_scrn_get_active_gui_buf();

    /* refresh prefer storage */
    if (g_mmi_phb_list_p->storage != mmi_phb_get_preferred_storage() ||
        g_mmi_phb_list_p->display_type != srv_phb_get_name_display_type())
    {
        g_mmi_phb_list_p->storage = (U8) mmi_phb_get_preferred_storage();
        g_mmi_phb_list_p->display_type = (U8) srv_phb_get_name_display_type();
        gui_buffer = NULL;
        g_mmi_phb_list_p->qsearch_input_buffer[0] = 0;
    }

    RegisterHighlightHandler(mmi_phb_quick_search_get_index_tab);
    RegisterCat200SearchFunction(mmi_phb_quick_search_find_entry_tab);

    if (gui_buffer == NULL)
    {
        filter = mmi_phb_list_build_filter(
                     g_mmi_phb_list_p->storage,
                     g_mmi_phb_list_p->filter,
                     &g_mmi_phb_list_p->group_filter,
                     NULL,
                     0);
        
        contact_count = (U16) srv_phb_oplib_build_contact_list(filter, g_mmi_phb_list_p->contact_array, MMI_PHB_ENTRIES);
        g_mmi_phb_list_p->contact_count = contact_count;
        
        mmi_phb_list_free_filter(filter);
        
        if (contact_count == 0)
        {
            g_mmi_phb_list_p->list_index = 0;        
        }
        else
        {
            g_mmi_phb_list_p->list_index = 1;
        }

        contact_count++;
    }
    else
    {
        if (!mmi_is_redrawing_bk_screens())
        {
            handle = mmi_phb_cntx_mgr_get_handle_by_sg_id(mmi_phb_cntx_mgr_get_current_sg_id());
            refresh_data = mmi_phb_cntx_mgr_get_refresh_data(handle);
        }
        if (!mmi_is_redrawing_bk_screens() &&
            refresh_data != NULL && refresh_data->refresh_type != MMI_PHB_OP_NONE)
        {
            gui_buffer = NULL;

            filter = mmi_phb_list_build_filter(
                         g_mmi_phb_list_p->storage,
                         g_mmi_phb_list_p->filter,
                         &g_mmi_phb_list_p->group_filter,
                         NULL,
                         0);
            
            contact_count = (U16) srv_phb_oplib_build_contact_list(filter, g_mmi_phb_list_p->contact_array, MMI_PHB_ENTRIES);
            g_mmi_phb_list_p->contact_count = contact_count;
            
            mmi_phb_list_free_filter(filter);

            if (contact_count == 0)
            {
                g_mmi_phb_list_p->list_index = 0;
            }
            else
            {
                g_mmi_phb_list_p->list_index = mmi_phb_calc_list_index(
                                                refresh_data,
                                                MMI_PHB_LIST_TYPE_SINGLE_SELECT,
                                                g_mmi_phb_list_p->list_index,
                                                g_mmi_phb_list_p->contact_array,
                                                NULL,
                                                g_mmi_phb_list_p->contact_count);

                g_mmi_phb_list_p->list_index++;
            }

            contact_count++;
            g_mmi_phb_list_p->qsearch_input_buffer[0] = 0;
            
            refresh_data->refresh_type = MMI_PHB_OP_NONE;
        }
        else
        {
            contact_count = (U16) mmi_phb_quick_search_find_entry_tab((U8 *) g_mmi_phb_list_p->qsearch_input_buffer);
        }
    }
    
#ifdef __MMI_UI_HINTS_IN_MENUITEM__
    set_force_icon_on_highlight_only_in_menuitem();
#endif

    EnableCenterSoftkey(0, IMG_GLOBAL_COMMON_CSK);

    wgui_fixed_list_register_get_flags_handler(mmi_phb_quick_search_list_seperate_line);

#ifdef __MMI_FTE_SUPPORT__
    item_icon[0] = get_image(IMG_GLOBAL_TOOLBAR_CALL);
    item_icon[1] = get_image(IMG_GLOBAL_TOOLBAR_SEND_MESSAGE);
    item_icon[2] = get_image(IMG_GLOBAL_TOOLBAR_EDIT);
    item_disable_icon[0] = get_image(IMG_GLOBAL_TOOLBAR_CALL_DISABLED);
    item_disable_icon[1] = get_image(IMG_GLOBAL_TOOLBAR_SEND_MESSAGE_DISABLED);
    item_disable_icon[2] = get_image(IMG_GLOBAL_TOOLBAR_EDIT_DISABLED);
    string[0] = (PU8)get_string((STR_GLOBAL_DIAL));
    string[1] = (PU8)get_string((STR_GLOBAL_SEND));
    string[2] = (PU8)get_string((STR_GLOBAL_EDIT));
    wgui_icon_bar_setup(item_count, item_icon, item_disable_icon, string, (GUIIconbarItemCallback)mmi_phb_fte_contact_list_callback);
#endif /* __MMI_FTE_SUPPORT__ */

    ShowCategory199Screen(
        (UI_string_type)GetString(STR_GLOBAL_OPTIONS),
        (PU8)GetImage(IMG_GLOBAL_OPTIONS),
        (UI_string_type)GetString(STR_GLOBAL_BACK),
        (PU8)GetImage(IMG_GLOBAL_BACK),
        0,        
        (UI_string_type)GetString(STR_SCR_PBOOK_VIEW_CAPTION),
        NULL,
        contact_count,
        mmi_phb_quick_search_list_get_item,
        mmi_phb_quick_search_list_get_hint,
        NULL,
        NULL,
        g_mmi_phb_list_p->list_index,
        (U8*) g_mmi_phb_list_p->qsearch_input_buffer,
        MMI_PHB_QUICK_SEARCH_INPUT_LENGTH,
        gui_buffer);

#ifdef __MMI_TOUCH_SCREEN__
    wgui_set_horizontal_tab_bar_select_callback(mmi_frm_set_cur_sel_page);
#endif /* __MMI_TOUCH_SCREEN__ */

    SetCategory200RightSoftkeyFunction(mmi_frm_scrn_close_active_id, KEY_EVENT_UP);

    SetCategory200LeftSoftkeyFunction(mmi_phb_entry_op_option, KEY_EVENT_UP);
    SetLeftSoftkeyFunction(mmi_phb_entry_op_option, KEY_EVENT_UP);

    SetCenterSoftkeyFunction(mmi_phb_quick_search_center_key_handlr, KEY_EVENT_UP);

#ifdef __MMI_FTE_SUPPORT__
    wgui_register_tap_callback(mmi_phb_fte_contact_list_tap_callback);
#endif /* __MMI_FTE_SUPPORT__ */
}


/*****************************************************************************
 * FUNCTION
 *  mmi_phb_exit_quick_search_list
 * DESCRIPTION
 *  
 * PARAMETERS
 *  void
 * RETURNS
 *  void
 *****************************************************************************/
static void mmi_phb_exit_quick_search_list(void)
{
    /*----------------------------------------------------------------*/
    /* Local Variables                                                */
    /*----------------------------------------------------------------*/

    /*----------------------------------------------------------------*/
    /* Code Body                                                      */
    /*----------------------------------------------------------------*/
    StopTimer(KEYPAD_LOCK_TIMER);

#if defined(__MMI_VRSD_DIAL__)
    StopTimer(VRSD_DIAL_PLAYBACK_TIMER);
#endif 

#if defined(__MMI_INTELLIGENT_CALL_ALERT__)
    mmi_phb_speak_name_end();
#endif /* defined(__MMI_INTELLIGENT_CALL_ALERT__) */
}


/*****************************************************************************
 * FUNCTION
 *  mmi_phb_entry_quick_search_list
 * DESCRIPTION
 *  
 * PARAMETERS
 *  void
 * RETURNS
 *  void
 *****************************************************************************/
static void mmi_phb_entry_quick_search_list(void)
{
    /*----------------------------------------------------------------*/
    /* Local Variables                                                */
    /*----------------------------------------------------------------*/
    U8 *gui_buffer;
    U16 contact_count;
    srv_phb_filter_struct * filter;
    U32 handle;
    mmi_phb_refresh_struct *refresh_data;
#ifdef __MMI_FTE_SUPPORT__
    S32 item_count = 3;
    PU8 item_icon[3] = {NULL, NULL, NULL};
    PU8 item_disable_icon[3] = {NULL, NULL, NULL};
    PU8 string[3] = {NULL, NULL, NULL};
#endif /* __MMI_FTE_SUPPORT__ */

    /*----------------------------------------------------------------*/
    /* Code Body                                                      */
    /*----------------------------------------------------------------*/
    if (!mmi_frm_scrn_enter(
            GRP_ID_PHB_MAIN,
            SCR_ID_PHB_QUICK_SEARCH_LIST,
            mmi_phb_exit_quick_search_list,
            mmi_phb_launch_entry,
            MMI_FRM_FULL_SCRN))
    {
        return;
    }

    gui_buffer = mmi_frm_scrn_get_active_gui_buf();
    
    RegisterHighlightHandler(mmi_phb_quick_search_get_index);
    RegisterCat200SearchFunction(mmi_phb_quick_search_find_entry);

    g_phb_quick_search_enter = MMI_PHB_QUICK_SEARCH_MAIN;

    /* refresh prefer storage */
    if (g_mmi_phb_list_p->storage != mmi_phb_get_preferred_storage() ||
        g_mmi_phb_list_p->display_type != srv_phb_get_name_display_type())
    {
        g_mmi_phb_list_p->storage = (U8) mmi_phb_get_preferred_storage();
        g_mmi_phb_list_p->display_type = (U8) srv_phb_get_name_display_type();
        gui_buffer = NULL;
        g_mmi_phb_list_p->qsearch_input_buffer[0] = 0;
    }
    
    if (gui_buffer == NULL)
    {
        filter = mmi_phb_list_build_filter(
                     g_mmi_phb_list_p->storage,
                     g_mmi_phb_list_p->filter,
                     NULL,
                     NULL,
                     0);
        
        contact_count = (U16) srv_phb_oplib_build_contact_list(filter, g_mmi_phb_list_p->contact_array, MMI_PHB_ENTRIES);
        g_mmi_phb_list_p->contact_count = contact_count;
        
        mmi_phb_list_free_filter(filter);
        
        if (contact_count == 0)
        {
            g_mmi_phb_list_p->list_index = 0;        
        }
        else
        {
            g_mmi_phb_list_p->list_index = 1;
        }

        contact_count++;
    }
    else
    {
        if (!mmi_is_redrawing_bk_screens())
        {
            handle = mmi_phb_cntx_mgr_get_handle_by_sg_id(mmi_phb_cntx_mgr_get_current_sg_id());
            refresh_data = mmi_phb_cntx_mgr_get_refresh_data(handle);
        }
        if (!mmi_is_redrawing_bk_screens() &&
            refresh_data != NULL && refresh_data->refresh_type != MMI_PHB_OP_NONE)
        {
            gui_buffer = NULL;

            filter = mmi_phb_list_build_filter(
                         g_mmi_phb_list_p->storage,
                         g_mmi_phb_list_p->filter,
                         &g_mmi_phb_list_p->group_filter,
                         NULL,
                         0);
            
            contact_count = (U16) srv_phb_oplib_build_contact_list(filter, g_mmi_phb_list_p->contact_array, MMI_PHB_ENTRIES);
            g_mmi_phb_list_p->contact_count = contact_count;
            
            mmi_phb_list_free_filter(filter);

            if (contact_count == 0)
            {
                g_mmi_phb_list_p->list_index = 0;
            }
            else
            {
                g_mmi_phb_list_p->list_index = mmi_phb_calc_list_index(
                                                refresh_data,
                                                MMI_PHB_LIST_TYPE_SINGLE_SELECT,
                                                g_mmi_phb_list_p->list_index,
                                                g_mmi_phb_list_p->contact_array,
                                                NULL,
                                                g_mmi_phb_list_p->contact_count);

                g_mmi_phb_list_p->list_index++;
            }

            contact_count++;
            g_mmi_phb_list_p->qsearch_input_buffer[0] = 0;
            
            refresh_data->refresh_type = MMI_PHB_OP_NONE;
        }
        else
        {
            contact_count = (U16) mmi_phb_quick_search_find_entry((U8 *) g_mmi_phb_list_p->qsearch_input_buffer);
        }
    }

    
#ifdef __MMI_UI_HINTS_IN_MENUITEM__
    set_force_icon_on_highlight_only_in_menuitem();
#endif

    mmi_imc_disable_csk();
    EnableCenterSoftkey(0, IMG_GLOBAL_COMMON_CSK);

    wgui_fixed_list_register_get_flags_handler(mmi_phb_quick_search_list_seperate_line);
    /* when refresh the list, then set the default highlight item to index = 1 */
    wgui_cat200_set_specific_highlight();

#ifdef __MMI_FTE_SUPPORT__
    item_icon[0] = get_image(IMG_GLOBAL_TOOLBAR_CALL);
    item_icon[1] = get_image(IMG_GLOBAL_TOOLBAR_SEND_MESSAGE);
    item_icon[2] = get_image(IMG_GLOBAL_TOOLBAR_EDIT);
    item_disable_icon[0] = get_image(IMG_GLOBAL_TOOLBAR_CALL_DISABLED);
    item_disable_icon[1] = get_image(IMG_GLOBAL_TOOLBAR_SEND_MESSAGE_DISABLED);
    item_disable_icon[2] = get_image(IMG_GLOBAL_TOOLBAR_EDIT_DISABLED);
    string[0] = (PU8)get_string((STR_GLOBAL_DIAL));
    string[1] = (PU8)get_string((STR_GLOBAL_SEND));
    string[2] = (PU8)get_string((STR_GLOBAL_EDIT));
    wgui_icon_bar_setup(item_count, item_icon, item_disable_icon, string, (GUIIconbarItemCallback)mmi_phb_fte_contact_list_callback);
#endif /* __MMI_FTE_SUPPORT__ */

    ShowCategory200Screen(
        STR_SCR_PBOOK_VIEW_CAPTION,
        IMG_SCR_PBOOK_CAPTION,
        STR_GLOBAL_OPTIONS,
        IMG_GLOBAL_OPTIONS,
        STR_GLOBAL_BACK,
        IMG_GLOBAL_BACK,
        contact_count,
        mmi_phb_quick_search_list_get_item,
        mmi_phb_quick_search_list_get_hint,
        g_mmi_phb_list_p->list_index,
        IMG_ID_PHB_QUICK_SEARCH_FIND,
        (U8*) g_mmi_phb_list_p->qsearch_input_buffer,
        MMI_PHB_QUICK_SEARCH_INPUT_LENGTH,
        gui_buffer);

    SetCategory200RightSoftkeyFunction(mmi_frm_scrn_close_active_id, KEY_EVENT_UP);

    SetCategory200LeftSoftkeyFunction(mmi_phb_entry_op_option, KEY_EVENT_UP);
    SetLeftSoftkeyFunction(mmi_phb_entry_op_option, KEY_EVENT_UP);
    
    SetCenterSoftkeyFunction(mmi_phb_quick_search_center_key_handlr, KEY_EVENT_UP);

#ifdef __MMI_FTE_SUPPORT__
    wgui_register_tap_callback(mmi_phb_fte_contact_list_tap_callback);
#endif /* __MMI_FTE_SUPPORT__ */
}


/*****************************************************************************
 * FUNCTION
 *  mmi_phb_quick_search_list_pre_entry
 * DESCRIPTION
 *  
 * PARAMETERS
 *  void
 * RETURNS
 *  void
 *****************************************************************************/
void mmi_phb_quick_search_list_pre_entry(void)
{
    /*----------------------------------------------------------------*/
    /* Local Variables                                                */
    /*----------------------------------------------------------------*/

    /*----------------------------------------------------------------*/
    /* Code Body                                                      */
    /*----------------------------------------------------------------*/
    mmi_phb_entry_main_menu();
}

#endif /* defined(__MMI_PHB_QUICK_SEARCH__) */


#define MMI_PHB_MULTI_SELECT
#if defined(__MMI_PHB_MULTI_OPERATION__) || defined(__MMI_PHB_GENERIC_MULTI_SELECT__)

/*****************************************************************************
 * FUNCTION
 *  mmi_phb_mark_several_highlight_hdlr
 * DESCRIPTION
 *  Highlight Handler for multi select
 * PARAMETERS
 *  item_index                   [IN]            highlight item index
 * RETURNS
 *  void
 *****************************************************************************/
static void mmi_phb_mark_several_highlight_hdlr(S32 item_index)
{
    /*----------------------------------------------------------------*/
    /* Local Variables                                                */
    /*----------------------------------------------------------------*/

    /*----------------------------------------------------------------*/
    /* Code Body                                                      */
    /*----------------------------------------------------------------*/
    g_mmi_phb_list_p->list_index = (U16) item_index;
    g_mmi_phb_list_p->store_index = g_mmi_phb_list_p->contact_array[item_index];

    ChangeCenterSoftkey(0, IMG_ID_PHB_CSK_MARK);

#if defined(__MMI_INTELLIGENT_CALL_ALERT__)
    mmi_phb_speak_name_start();
#endif
}


/*****************************************************************************
 * FUNCTION
 *  mmi_phb_bitmask_set_state
 * DESCRIPTION
 *  set a bit of bit_mask
 * PARAMETERS
 *  bit_mask      [IN]
 *  index         [IN]
 *  status        [IN]
 * RETURNS
 *  void
 *****************************************************************************/
void mmi_phb_bitmask_set_state(U8* bit_mask, U16 store_index, MMI_BOOL status)
{
    /*----------------------------------------------------------------*/
    /* Local Variables                                                */
    /*----------------------------------------------------------------*/

    /*----------------------------------------------------------------*/
    /* Code Body                                                      */
    /*----------------------------------------------------------------*/
    if (status)
    {
        bit_mask[store_index >> BYTE_SIZE_SHIFT_ARITHMETIC] |= 1 << (store_index % BYTE_SIZE);
    }
    else
    {
        bit_mask[store_index >> BYTE_SIZE_SHIFT_ARITHMETIC] &= (kal_uint8)(~(1 << (store_index % BYTE_SIZE)));
    }
}


/*****************************************************************************
 * FUNCTION
 *  mmi_phb_bitmask_get_state
 * DESCRIPTION
 *  get a bit state of bitmask
 * PARAMETERS
 *  bit_mask      [IN]
 *  index         [IN]
 * RETURNS
 *  0 is false, else is true
 *****************************************************************************/
static U8 mmi_phb_bitmask_get_state(U8* bit_mask, U16 store_index)
{
    /*----------------------------------------------------------------*/
    /* Local Variables                                                */
    /*----------------------------------------------------------------*/

    /*----------------------------------------------------------------*/
    /* Code Body                                                      */
    /*----------------------------------------------------------------*/
    return bit_mask[store_index >> BYTE_SIZE_SHIFT_ARITHMETIC] & (1 << (store_index % BYTE_SIZE));
}


/*****************************************************************************
 * FUNCTION
 *  mmi_phb_bitmask_change_state
 * DESCRIPTION
 *  change a bit of bit_mask
 * PARAMETERS
 *  bit_mask      [IN]
 *  index         [IN]
 * RETURNS
 *  void
 *****************************************************************************/
static void mmi_phb_bitmask_change_state(U8* bit_mask, U16 store_index)
{
    /*----------------------------------------------------------------*/
    /* Local Variables                                                */
    /*----------------------------------------------------------------*/

    /*----------------------------------------------------------------*/
    /* Code Body                                                      */
    /*----------------------------------------------------------------*/
    bit_mask[store_index >> BYTE_SIZE_SHIFT_ARITHMETIC] ^= (kal_uint8)(1 << (store_index % BYTE_SIZE));
}


/*****************************************************************************
 * FUNCTION
 *  mmi_phb_mark_several_count
 * DESCRIPTION
 *  caculate phonebook list multi select count
 * PARAMETERS
 *  void
 * RETURNS
 *  U16
 *****************************************************************************/
static U16 mmi_phb_mark_several_count(void)
{
    /*----------------------------------------------------------------*/
    /* Local Variables                                                */
    /*----------------------------------------------------------------*/
    U16 i;
    U16 mark_count = 0;
    
    /*----------------------------------------------------------------*/
    /* Code Body                                                      */
    /*----------------------------------------------------------------*/
    for (i = 0; i < MMI_PHB_ENTRIES; i++)
    {
        if (mmi_phb_bitmask_get_state(g_mmi_phb_list_p->bitmask, i))
        {
            mark_count++;
        }
    }

    return mark_count;
}


/*****************************************************************************
 * FUNCTION
 *  mmi_phb_mark_several_set_state
 * DESCRIPTION
 *  set check box state
 * PARAMETERS
 *  void
 * RETURNS
 *  void
 *****************************************************************************/
static S32 mmi_phb_mark_several_set_state(S32 item_index)
{
    /*----------------------------------------------------------------*/
    /* Local Variables                                                */
    /*----------------------------------------------------------------*/    
    U16 mark_count = 0;

    /*----------------------------------------------------------------*/
    /* Code Body                                                      */
    /*----------------------------------------------------------------*/
    if (g_mmi_phb_list_p->contact_count == 0)
    {
        return MMI_FALSE;
    }
    
    mmi_phb_bitmask_change_state(g_mmi_phb_list_p->bitmask, g_mmi_phb_list_p->contact_array[item_index]);

    if (mmi_phb_bitmask_get_state(g_mmi_phb_list_p->bitmask, g_mmi_phb_list_p->contact_array[item_index]))
    {
        mark_count = mmi_phb_mark_several_count();
        
        if (mark_count > g_mmi_phb_list_p->select_count)
        {
            mmi_phb_bitmask_change_state(g_mmi_phb_list_p->bitmask, g_mmi_phb_list_p->contact_array[item_index]);
            mmi_popup_display_simple(
                (UI_string_type)GetString(STR_ID_PHB_MULTI_OP_MAX_ITEM_REACH),
                MMI_EVENT_FAILURE,
                g_mmi_phb_list_p->sg_id,
                NULL);

            return MMI_FALSE;
        }
    }

    return MMI_TRUE;
}


/*****************************************************************************
 * FUNCTION
 *  mmi_phb_mark_several_get_state
 * DESCRIPTION
 *  get check box state
 * PARAMETERS
 *  void
 * RETURNS
 *  S32
 *****************************************************************************/
static S32 mmi_phb_mark_several_get_state(S32 item_index, PU8 *checkbox_image)
{
    /*----------------------------------------------------------------*/
    /* Local Variables                                                */
    /*----------------------------------------------------------------*/

    /*----------------------------------------------------------------*/
    /* Code Body                                                      */
    /*----------------------------------------------------------------*/
    *checkbox_image = (mmi_phb_bitmask_get_state(g_mmi_phb_list_p->bitmask, g_mmi_phb_list_p->contact_array[item_index])) ?
                      (PU8)GetImage(CHECKBOX_ON_IMAGE_ID) :
                      (PU8)GetImage(CHECKBOX_OFF_IMAGE_ID) ;
    return MMI_TRUE;
}


/*****************************************************************************
 * FUNCTION
 *  mmi_phb_multi_select_check
 * DESCRIPTION
 *  set check box
 * PARAMETERS
 *  void
 * RETURNS
 *  void
 *****************************************************************************/
void mmi_phb_mark_several_check(void)
{
    /*----------------------------------------------------------------*/
    /* Local Variables                                                */
    /*----------------------------------------------------------------*/

    /*----------------------------------------------------------------*/
    /* Code Body                                                      */
    /*----------------------------------------------------------------*/
    if (mmi_phb_mark_several_set_state(g_mmi_phb_list_p->list_index) == MMI_TRUE)
    {
        RedrawCategoryFunction();
    }
}


/*****************************************************************************
 * FUNCTION
 *  mmi_phb_mark_several_populate
 * DESCRIPTION
 *  caculate phonebook list multi select count
 * PARAMETERS
 *  void
 * RETURNS
 *  U16
 *****************************************************************************/
U16 mmi_phb_mark_several_populate(void)
{
    /*----------------------------------------------------------------*/
    /* Local Variables                                                */
    /*----------------------------------------------------------------*/
    U16 i;
    U16 mark_count = 0;
    
    /*----------------------------------------------------------------*/
    /* Code Body                                                      */
    /*----------------------------------------------------------------*/    
    for (i = 0; i < MMI_PHB_ENTRIES; i++)
    {
        if (mmi_phb_bitmask_get_state(g_mmi_phb_list_p->bitmask, i))
        {
            /* i = store_index */
            g_mmi_phb_list_p->mark_array[mark_count++] = i;
        }
    }

    g_mmi_phb_list_p->mark_count = mark_count;
    
    return mark_count;
}

static U16 mmi_phb_mark_several_search_count(void)
{
    /*----------------------------------------------------------------*/
    /* Local Variables                                                */
    /*----------------------------------------------------------------*/
    U16 index = 0;
    U16 count = 0;

    /*----------------------------------------------------------------*/
    /* Code Body                                                      */
    /*----------------------------------------------------------------*/    
    for(index = 0; index < g_mmi_phb_list_p->contact_count; index++)
    {
        if (mmi_phb_bitmask_get_state(g_mmi_phb_list_p->bitmask, g_mmi_phb_list_p->contact_array[index]))
        {
            count++;
        }
    }

    return count;
}


/*****************************************************************************
 * FUNCTION
 *  mmi_phb_star_key_pre_handler
 * DESCRIPTION
 *  register pre handler of '*' to inputmethod
 * PARAMETERS
 *  key_code
 *  key_type
 * RETURNS
 *  MMI_BOOL
 *****************************************************************************/
MMI_BOOL mmi_phb_star_key_pre_handler(U16 key_code, U16 key_type)
{
    /*----------------------------------------------------------------*/
    /* Local Variables                                                */
    /*----------------------------------------------------------------*/

    /*----------------------------------------------------------------*/
    /* Code Body                                                      */
    /*----------------------------------------------------------------*/
    if (key_code == KEY_STAR)
    {
        if (key_type == KEY_EVENT_UP)
        {
            if (mmi_phb_mark_several_set_state(g_mmi_phb_list_p->list_index) == MMI_TRUE)
            {
                RedrawCategoryFunction();
            }
        }
        return MMI_TRUE;
    }
    return MMI_FALSE;
}

#endif


/*****************************************************************************
 * FUNCTION
 *  mmi_phb_continue_send_multi_message_confirm
 * DESCRIPTION
 *  confirm mark several copy
 * PARAMETERS
 *  void
 * RETURNS
 *  void
 *****************************************************************************/
void mmi_phb_continue_send_multi_message_confirm(U16 max_count, MenucuiPtr lsk_ptr, MenucuiPtr rsk_ptr, MMI_ID group_id)
{
    /*----------------------------------------------------------------*/
    /* Local Variables                                                */
    /*----------------------------------------------------------------*/
    U16 outBuf[50];
    mmi_confirm_property_struct arg;

    /*----------------------------------------------------------------*/
    /* Code Body                                                      */
    /*----------------------------------------------------------------*/
    if (max_count > 1)
    {
        kal_wsprintf(
            outBuf, 
            "%w %d %w",
            GetString(STR_ID_PHB_SEND_MULTI_MESSAGE_QUERY_1),
            max_count,
            GetString(STR_ID_PHB_SEND_MULTI_MESSAGE_QUERY_2));
    }
    else
    {
        kal_wsprintf(
            outBuf, 
            "%w %d %w",
            GetString(STR_ID_PHB_SEND_MULTI_MESSAGE_QUERY_1),
            max_count,
            GetString(STR_ID_PHB_SEND_MULTI_MESSAGE_QUERY_3));
    }
    /*mmi_phb_display_confirm(
        (UI_string_type) GetString(STR_GLOBAL_YES),
        (U8*) GetImage(IMG_GLOBAL_YES), 
        (UI_string_type) GetString(STR_GLOBAL_NO),
        (U8*) GetImage(IMG_GLOBAL_NO), 
        (UI_string_type) outBuf,
        MMI_EVENT_QUERY);

    SetLeftSoftkeyFunction(lsk_ptr, KEY_EVENT_UP);
    SetRightSoftkeyFunction(rsk_ptr, KEY_EVENT_UP);*/
    mmi_confirm_property_init(&arg, CNFM_TYPE_YESNO);
    arg.parent_id = group_id;
    arg.callback = (mmi_proc_func)mmi_phb_comfirm_proc;

    mmi_phb_confirm_user_data_init(&g_mmi_phb_confirm_user_data);
    g_mmi_phb_confirm_user_data.sg_id = group_id;
    g_mmi_phb_confirm_user_data.LSK_function = lsk_ptr;
    g_mmi_phb_confirm_user_data.RSK_function = rsk_ptr;

    arg.user_tag = (void *)&g_mmi_phb_confirm_user_data;

    mmi_confirm_display(
        (WCHAR *) outBuf,
        MMI_EVENT_QUERY,
        &arg);
}


#if defined(__MMI_PHB_MULTI_OPERATION__)

/*****************************************************************************
 * FUNCTION
 *  mmi_phb_mark_several_main_build_option
 * DESCRIPTION
 *  build mark several main option menu
 * PARAMETERS
 *  void
 * RETURNS
 *  void
 *****************************************************************************/
void mmi_phb_mark_several_main_build_option(MMI_ID menu_gid)
{
    /*----------------------------------------------------------------*/
    /* Local Variables                                                */
    /*----------------------------------------------------------------*/

    /*----------------------------------------------------------------*/
    /* Code Body                                                      */
    /*----------------------------------------------------------------*/
    if (g_mmi_phb_list_p->mark_count > 0)
    {
    #ifdef __MMI_PHB_SEND_MSG__
    #ifdef __MMI_UNIFIED_COMPOSER__
        if (mmi_uc_is_uc_ready())
        {
            cui_menu_set_item_hidden(menu_gid, MENU_ID_PHB_MARK_SEVERAL_OP_SEND_MESSAGE, MMI_FALSE);
        }
    #else
        if (!srv_sms_is_hide_send_sms_menu_item())
        {
            cui_menu_set_item_hidden(menu_gid, MENU_ID_PHB_MARK_SEVERAL_OP_SEND_SMS, MMI_FALSE);
        }
    #if defined(__MMI_MMS__) &&  defined(OBIGO_Q03C_MMS_V02) && !defined(__MMI_SLIM_MMS_2__)
        if (mms_is_ready())
        {
            cui_menu_set_item_hidden(menu_gid, MENU_ID_PHB_MARK_SEVERAL_OP_SEND_MMS, MMI_FALSE);
        }
    #endif /* defined(OBIGO_Q03C_MMS_V02) &&  defined(__MMI_MMS__) */
    #endif /* __MMI_UNIFIED_COMPOSER__ */
    #endif /*__MMI_PHB_SEND_MSG__ */
        cui_menu_set_item_hidden(menu_gid, MENU_ID_PHB_MARK_SEVERAL_OP_DELETE_SELECTED, MMI_FALSE);
    #ifdef __MMI_UDX_VCARD_SUPPORT__
        cui_menu_set_item_hidden(menu_gid, MENU_ID_PHB_MARK_SEVERAL_OP_BUILD_UDX, MMI_FALSE);
    #endif
    #if defined(__MMI_VCARD__) && defined(__MMI_OPP_SUPPORT__)
        if (mmi_bt_is_to_display_bt_menu())
        {
            cui_menu_set_item_hidden(menu_gid, MENU_ID_PHB_MARK_SEVERAL_OP_SEND_VCARD, MMI_FALSE);
        }
    #endif
    }
}


/*****************************************************************************
 * FUNCTION
 *  mmi_phb_mark_several_copy_build_option
 * DESCRIPTION
 *  build mark several copy option menu
 * PARAMETERS
 *  void
 * RETURNS
 *  void
 *****************************************************************************/
void mmi_phb_mark_several_copy_build_option(MMI_ID menu_gid)
{
    /*----------------------------------------------------------------*/
    /* Local Variables                                                */
    /*----------------------------------------------------------------*/

    /*----------------------------------------------------------------*/
    /* Code Body                                                      */
    /*----------------------------------------------------------------*/    
    if (g_mmi_phb_list_p->mark_count > 0)
    {
        cui_menu_set_item_hidden(menu_gid, MENU_ID_PHB_MARK_SEVERAL_OP_COPY_SELECTED, MMI_FALSE);
    }
}


/*****************************************************************************
 * FUNCTION
 *  mmi_phb_mark_several_move_build_option
 * DESCRIPTION
 *  build mark several move option menu
 * PARAMETERS
 *  void
 * RETURNS
 *  void
 *****************************************************************************/
void mmi_phb_mark_several_move_build_option(MMI_ID menu_gid)
{
    /*----------------------------------------------------------------*/
    /* Local Variables                                                */
    /*----------------------------------------------------------------*/

    /*----------------------------------------------------------------*/
    /* Code Body                                                      */
    /*----------------------------------------------------------------*/    
    if (g_mmi_phb_list_p->mark_count > 0)
    {
        cui_menu_set_item_hidden(menu_gid, MENU_ID_PHB_MARK_SEVERAL_OP_MOVE_SELECTED, MMI_FALSE);
    }
}

#define MARK_SEVERAL_OPTION


#ifdef __MMI_PHB_SEND_MSG__



/*****************************************************************************
 * FUNCTION
 *  mmi_phb_mark_several_send_message_go_back_histoty
 * DESCRIPTION
 *  Go back screen after change input method.
 * PARAMETERS
 *  void
 * RETURNS
 *  void
 *****************************************************************************/
void mmi_phb_mark_several_send_message_go_back_histoty(void)
{
    /*----------------------------------------------------------------*/
    /* Local Variables                                                */
    /*----------------------------------------------------------------*/

    /*----------------------------------------------------------------*/
    /* Code Body                                                      */
    /*----------------------------------------------------------------*/
    mmi_frm_scrn_close(GRP_ID_PHB_MARK_SEVERAL, SCR_ID_PHB_MULTI_OP_OPTION);
    mmi_frm_scrn_close_active_id();
}


void mmi_phb_mark_several_send_message_go_back_histoty_ext(MMI_ID group_id)
{
    mmi_phb_mark_several_send_message_go_back_histoty();
}


/*****************************************************************************
 * FUNCTION
 *  mmi_phb_mark_several_get_address_callback
 * DESCRIPTION
 *  Highlight handler for "send message" in PHB -> mark several -> Option
 * PARAMETERS
 *  void
 * RETURNS
 *  void
 *****************************************************************************/
U8* mmi_phb_mark_several_get_address_callback(U16 index, U16* type)
{
    /*----------------------------------------------------------------*/
    /* Local Variables                                                */
    /*----------------------------------------------------------------*/

    /*----------------------------------------------------------------*/
    /* Code Body                                                      */
    /*----------------------------------------------------------------*/
#if !defined(__MMI_PHB_NO_OPTIONAL_FIELD__) 
    if (g_mmi_phb_list_p->mark_field[index] & SRV_PHB_ENTRY_FIELD_EMAIL1)
    {   
        *type = MMI_PHB_ADDRESS_TYPE_EMAIL;
        srv_phb_get_email_address(g_mmi_phb_list_p->mark_array[index], g_mmi_phb_temp_buffer, MMI_PHB_EMAIL_LENGTH);
    }
#if defined(__MMI_PHB_OPTIONAL_FIELDS_2ND_EMAIL__)    
    else if (g_mmi_phb_list_p->mark_field[index] & SRV_PHB_ENTRY_FIELD_EMAIL2)
    {
        *type = MMI_PHB_ADDRESS_TYPE_EMAIL;
        srv_phb_get_email_address2(g_mmi_phb_list_p->mark_array[index], g_mmi_phb_temp_buffer, MMI_PHB_EMAIL_LENGTH);
    }
#endif /* __MMI_PHB_OPTIONAL_FIELDS_2ND_EMAIL__ */    
    else
#endif
    {
        *type = MMI_PHB_ADDRESS_TYPE_NUMBER;
        srv_phb_get_number(g_mmi_phb_list_p->mark_array[index], g_mmi_phb_temp_buffer, (U16) (MMI_PHB_NUMBER_LENGTH + 1));
    }
    
    return (U8*)g_mmi_phb_temp_buffer;
}


/*****************************************************************************
 * FUNCTION
 *  mmi_phb_mark_several_filter_for_send_message
 * DESCRIPTION
 *  Highlight handler for "send message" in PHB -> mark several -> Option
 * PARAMETERS
 *  void
 * RETURNS
 *  void
 *****************************************************************************/
MMI_BOOL mmi_phb_mark_several_filter_for_send_message(U16 max_count, U16 filter)
{
    /*----------------------------------------------------------------*/
    /* Local Variables                                                */
    /*----------------------------------------------------------------*/
    U16 i, store_index;
    U16 end;
    U16 tmp;
    U32 contact_filter;
    
    /*----------------------------------------------------------------*/
    /* Code Body                                                      */
    /*----------------------------------------------------------------*/   
    end = g_mmi_phb_list_p->mark_count;
    for (i = 0; i < end;)
    {
        if (i >= max_count)
        {
            g_mmi_phb_op_cntx.total_count = max_count;
            return MMI_TRUE;
        }
        store_index = g_mmi_phb_list_p->mark_array[i];
        srv_phb_get_field(store_index, &contact_filter);
        
        if (!(contact_filter & filter))
        {
            end--;
            tmp = g_mmi_phb_list_p->mark_array[i];
            g_mmi_phb_list_p->mark_array[i] = g_mmi_phb_list_p->mark_array[end];
            g_mmi_phb_list_p->mark_array[end] = tmp;
        }
        else
        {
            i++;
        }
    }
    
    g_mmi_phb_op_cntx.total_count = end;
    return MMI_FALSE;
}


#ifdef __MMI_UNIFIED_COMPOSER__


/*****************************************************************************
 * FUNCTION
 *  mmi_phb_mark_several_send_mms_choose_address_more
 * DESCRIPTION
 *  Highlight handler for "send message" in PHB -> mark several -> Option
 * PARAMETERS
 *  void
 * RETURNS
 *  void
 *****************************************************************************/
void mmi_phb_mark_several_send_uc_choose_address_more(void)
{
    /*----------------------------------------------------------------*/
    /* Local Variables                                                */
    /*----------------------------------------------------------------*/

    /*----------------------------------------------------------------*/
    /* Code Body                                                      */
    /*----------------------------------------------------------------*/
    g_mmi_phb_list_p->mark_field[g_mmi_phb_op_cntx.active_index++] = g_mmi_phb_choose_field.number_type[g_mmi_phb_choose_field.highlight_index];
    mmi_frm_display_dummy_screen();
    mmi_frm_scrn_close(GRP_ID_PHB_MARK_SEVERAL, SCR_CHOOSE_NUMBER);

    if (g_mmi_phb_op_cntx.active_index < g_mmi_phb_op_cntx.total_count)
    {
        mmi_phb_entry_mark_several_send_uc_choose_address();
    }
    else
    {
        mmi_phb_entry_mark_several_send_uc();
    }
}


/*****************************************************************************
 * FUNCTION
 *  mmi_phb_entry_mark_several_send_mms_choose_address
 * DESCRIPTION
 *  Highlight handler for "send message" in PHB -> mark several -> Option
 * PARAMETERS
 *  void
 * RETURNS
 *  void
 *****************************************************************************/
void mmi_phb_entry_mark_several_send_uc_choose_address(void)
{
    /*----------------------------------------------------------------*/
    /* Local Variables                                                */
    /*----------------------------------------------------------------*/

    /*----------------------------------------------------------------*/
    /* Code Body                                                      */
    /*----------------------------------------------------------------*/
    mmi_phb_entry_choose_field(
        g_mmi_phb_list_p->sg_id,
        g_mmi_phb_list_p->mark_array[g_mmi_phb_op_cntx.active_index],
        SRV_PHB_ENTRY_FIELD_MMS_PHB,
        mmi_phb_entry_mark_several_send_uc_choose_address,
        mmi_phb_mark_several_send_uc_choose_address_more,
        mmi_phb_mark_several_send_message_go_back_histoty,
        NULL,
        MMI_FALSE,
        MMI_TRUE);
}


/*****************************************************************************
 * FUNCTION
 *  mmi_phb_entry_mark_several_send_mms
 * DESCRIPTION
 *  Highlight handler for "send message" in PHB -> mark several -> Option
 * PARAMETERS
 *  void
 * RETURNS
 *  void
 *****************************************************************************/
void mmi_phb_mark_several_send_uc_choose_address(MMI_ID group_id)
{
    /*----------------------------------------------------------------*/
    /* Local Variables                                                */
    /*----------------------------------------------------------------*/

    /*----------------------------------------------------------------*/
    /* Code Body                                                      */
    /*----------------------------------------------------------------*/
    if (g_mmi_phb_op_cntx.total_count)
    {
        g_mmi_phb_op_cntx.active_index = 0;
        mmi_phb_entry_mark_several_send_uc_choose_address();
    }
    else
    {
        mmi_popup_display(
            (WCHAR *)GetString(STR_SMS_NUM_CANNOT_BE_EMPTY),
            MMI_EVENT_FAILURE,
            NULL);

        mmi_frm_group_close(GRP_ID_PHB_MARK_SEVERAL);
    }
}


/*****************************************************************************
 * FUNCTION
 *  mmi_phb_entry_mark_several_send_message
 * DESCRIPTION
 *  Highlight handler for "send message" in PHB -> mark several -> Option
 * PARAMETERS
 *  void
 * RETURNS
 *  void
 *****************************************************************************/
void mmi_phb_entry_mark_several_send_uc(void)
{
    /*----------------------------------------------------------------*/
    /* Local Variables                                                */
    /*----------------------------------------------------------------*/
    mmi_uc_entry_write_struct data = {0,};

    /*----------------------------------------------------------------*/
    /* Code Body                                                      */
    /*----------------------------------------------------------------*/
    data.addr_num = (U8)g_mmi_phb_op_cntx.total_count;
    data.get_address_callback = (uc_func_ptr_general_insert_get_addr_fn)mmi_phb_mark_several_get_address_callback;
    data.addr = NULL;
    data.msg_type = MMI_UC_MSG_TYPE_DEFAULT;
    mmi_uc_entry_write_msg_with_content(MMI_UC_STATE_WRITE_NEW_MSG, &data);

    mmi_frm_group_close(GRP_ID_PHB_MARK_SEVERAL);
}


/*****************************************************************************
 * FUNCTION
 *  mmi_phb_pre_entry_mark_several_send_uc
 * DESCRIPTION
 *  Highlight handler for "send message" in PHB -> mark several -> Option
 * PARAMETERS
 *  void
 * RETURNS
 *  void
 *****************************************************************************/
void mmi_phb_pre_entry_mark_several_send_uc(void)
{
    /*----------------------------------------------------------------*/
    /* Local Variables                                                */
    /*----------------------------------------------------------------*/
    U16 max_count;
    
    /*----------------------------------------------------------------*/
    /* Code Body                                                      */
    /*----------------------------------------------------------------*/
    if (IsMessagesReEntering())
    {
        mmi_popup_display(
            (WCHAR *)GetString(STR_GLOBAL_NOT_AVAILABLE),
            MMI_EVENT_FAILURE,
            NULL);

        mmi_frm_group_close(GRP_ID_PHB_MARK_SEVERAL);
    }
    else 
    {
        max_count = wap_custom_get_max_mms_address();
        if (mmi_phb_mark_several_filter_for_send_message(max_count, SRV_PHB_ENTRY_FIELD_MMS_PHB))
        {
            mmi_phb_continue_send_multi_message_confirm(
                max_count,
                mmi_phb_mark_several_send_uc_choose_address,
                mmi_phb_mark_several_send_message_go_back_histoty_ext,
                GRP_ID_PHB_MARK_SEVERAL);
        }
        else
        {
            mmi_phb_mark_several_send_uc_choose_address(GRP_ID_PHB_MARK_SEVERAL);
        }
    }
}


/*****************************************************************************
 * FUNCTION
 *  mmi_phb_highlight_mark_several_send_message
 * DESCRIPTION
 *  Highlight handler for "send message" in PHB -> mark several -> Option
 * PARAMETERS
 *  void
 * RETURNS
 *  void
 *****************************************************************************/
void mmi_phb_highlight_mark_several_send_message(void)
{
    /*----------------------------------------------------------------*/
    /* Local Variables                                                */
    /*----------------------------------------------------------------*/

    /*----------------------------------------------------------------*/
    /* Code Body                                                      */
    /*----------------------------------------------------------------*/
    ChangeLeftSoftkey(STR_GLOBAL_OK, IMG_GLOBAL_OK);
    ChangeRightSoftkey(STR_GLOBAL_BACK, IMG_GLOBAL_BACK);
    
    SetLeftSoftkeyFunction(mmi_phb_pre_entry_mark_several_send_uc, KEY_EVENT_UP);
    SetRightSoftkeyFunction(mmi_frm_scrn_close_active_id, KEY_EVENT_UP);
}


#else /*__MMI_UNIFIED_COMPOSER__ */


/*****************************************************************************
 * FUNCTION
 *  mmi_phb_entry_mark_several_send_sms
 * DESCRIPTION
 *  Highlight handler for "send message" in PHB -> mark several -> Option
 * PARAMETERS
 *  void
 * RETURNS
 *  void
 *****************************************************************************/
void mmi_phb_entry_mark_several_send_sms(MMI_ID group_id)
{
    /*----------------------------------------------------------------*/
    /* Local Variables                                                */
    /*----------------------------------------------------------------*/

    /*----------------------------------------------------------------*/
    /* Code Body                                                      */
    /*----------------------------------------------------------------*/
    if (g_mmi_phb_op_cntx.total_count)
    {
        mmi_sms_entry_write_msg_from_phb(
            g_mmi_phb_op_cntx.total_count,
            (void*)mmi_phb_mark_several_get_address_callback);
    }
    else
    {
        mmi_popup_display(
            (WCHAR *)GetString(STR_SMS_NUM_CANNOT_BE_EMPTY),
            MMI_EVENT_FAILURE,
            NULL);
    }

    mmi_frm_group_close(GRP_ID_PHB_MARK_SEVERAL);
}



/*****************************************************************************
 * FUNCTION
 *  mmi_phb_pre_entry_mark_several_send_sms
 * DESCRIPTION
 *  Highlight handler for "send message" in PHB -> mark several -> Option
 * PARAMETERS
 *  void
 * RETURNS
 *  void
 *****************************************************************************/
void mmi_phb_pre_entry_mark_several_send_sms(void)
{
    /*----------------------------------------------------------------*/
    /* Local Variables                                                */
    /*----------------------------------------------------------------*/
    U16 max_count;
    mmi_id sg_id = GRP_ID_PHB_MARK_SEVERAL;

    /*----------------------------------------------------------------*/
    /* Code Body                                                      */
    /*----------------------------------------------------------------*/
    if (mmi_sms_is_reenter_message())
    {
        mmi_frm_scrn_close(sg_id, SCR_ID_PHB_MULTI_OP_PHB_LIST);
        return;
    }

    max_count = mmi_sms_get_max_recipient_num();
    if (mmi_phb_mark_several_filter_for_send_message(max_count, SRV_PHB_ENTRY_FIELD_NUMBER))
    {
        mmi_phb_continue_send_multi_message_confirm(
            max_count,
            mmi_phb_entry_mark_several_send_sms,
            mmi_phb_mark_several_send_message_go_back_histoty_ext,
            GRP_ID_PHB_MARK_SEVERAL);
    }
    else
    {
        mmi_phb_entry_mark_several_send_sms(GRP_ID_PHB_MARK_SEVERAL);
    }
}


/*****************************************************************************
 * FUNCTION
 *  mmi_phb_highlight_mark_several_send_sms
 * DESCRIPTION
 *  Highlight handler for "send message" in PHB -> mark several -> Option
 * PARAMETERS
 *  void
 * RETURNS
 *  void
 *****************************************************************************/
void mmi_phb_highlight_mark_several_send_sms(void)
{
    /*----------------------------------------------------------------*/
    /* Local Variables                                                */
    /*----------------------------------------------------------------*/

    /*----------------------------------------------------------------*/
    /* Code Body                                                      */
    /*----------------------------------------------------------------*/
    ChangeLeftSoftkey(STR_GLOBAL_OK, IMG_GLOBAL_OK);
    ChangeRightSoftkey(STR_GLOBAL_BACK, IMG_GLOBAL_BACK);
    
    SetLeftSoftkeyFunction(mmi_phb_pre_entry_mark_several_send_sms, KEY_EVENT_UP);
    SetRightSoftkeyFunction(mmi_frm_scrn_close_active_id, KEY_EVENT_UP);
}

#if defined(__MMI_MMS__) &&  defined(OBIGO_Q03C_MMS_V02) && !defined(__MMI_SLIM_MMS_2__)


/*****************************************************************************
 * FUNCTION
 *  mmi_phb_mark_several_send_mms_rsp
 * DESCRIPTION
 *  Highlight handler for "send message" in PHB -> mark several -> Option
 * PARAMETERS
 *  void
 * RETURNS
 *  void
 *****************************************************************************/
void mmi_phb_mark_several_send_mms_rsp(void *info)
{
    /*----------------------------------------------------------------*/
    /* Local Variables                                                */
    /*----------------------------------------------------------------*/
    mms_multi_object_insert_rsp_struct *local_buffer;

    /*----------------------------------------------------------------*/
    /* Code Body                                                      */
    /*----------------------------------------------------------------*/
    local_buffer = (mms_multi_object_insert_rsp_struct *)info;
    if (local_buffer->result && g_mmi_phb_op_cntx.active_index < g_mmi_phb_op_cntx.total_count)
    {
        mmi_phb_mark_several_send_mms_insert_more_ind(local_buffer->request_id);
	}
	else
	{
	    mmi_frm_group_close(GRP_ID_PHB_MARK_SEVERAL);
    }
}


/*****************************************************************************
 * FUNCTION
 *  mmi_phb_mark_several_send_mms_req
 * DESCRIPTION
 *  Highlight handler for "send message" in PHB -> mark several -> Option
 * PARAMETERS
 *  void
 * RETURNS
 *  void
 *****************************************************************************/
void mmi_phb_mark_several_send_mms_req(void)
{
    /*----------------------------------------------------------------*/
    /* Local Variables                                                */
    /*----------------------------------------------------------------*/
    MYQUEUE Message;
    mms_multi_object_insert_req_struct *local_buffer;
    peer_buff_struct *peer_buffer;
    U16 start_index, end_index;
    U8 *peer_pdu;
    U16 peer_pdu_len;
    
    /*----------------------------------------------------------------*/
    /* Code Body                                                      */
    /*----------------------------------------------------------------*/
    local_buffer = (mms_multi_object_insert_req_struct*) OslConstructDataPtr(sizeof(mms_multi_object_insert_req_struct));

    local_buffer->request_id = mma_get_request_id();
    start_index = 0;
    end_index = start_index +  MAX_MMS_OBJECT;
    if (end_index  < g_mmi_phb_op_cntx.total_count)
    {
        local_buffer->more = MMI_TRUE;
    }
    else
    {
        local_buffer->more = MMI_FALSE;
        end_index = g_mmi_phb_op_cntx.total_count;
    }
    local_buffer->num_of_object = end_index - start_index;
    g_mmi_phb_op_cntx.active_index = end_index;

    peer_pdu_len = local_buffer->num_of_object * sizeof(mms_multi_object_struct);
    peer_buffer = construct_peer_buff(peer_pdu_len, 0, 0, TD_CTRL);
    peer_pdu = (U8*) get_pdu_ptr(peer_buffer, &peer_pdu_len);

    mmi_phb_mark_several_send_mms_prepare_buffer(
            start_index,
            end_index,
            peer_pdu);
            
    Message.oslSrcId = MOD_MMI;
    Message.oslDestId = mms_get_service_module(MSG_ID_MMS_MULTI_OBJECT_INSERT_REQ);
    Message.oslMsgId = MSG_ID_MMS_MULTI_OBJECT_INSERT_REQ;
    Message.oslDataPtr = (oslParaType*) local_buffer;
    Message.oslPeerBuffPtr = (peer_buff_struct*)peer_buffer;

    SetProtocolEventHandler(mmi_phb_mark_several_send_mms_rsp, MSG_ID_MMS_MULTI_OBJECT_INSERT_RSP);
    OslMsgSendExtQueue(&Message);
}


/*****************************************************************************
 * FUNCTION
 *  mmi_phb_mark_several_send_mms_insert_more_ind
 * DESCRIPTION
 *  Highlight handler for "send message" in PHB -> mark several -> Option
 * PARAMETERS
 *  void
 * RETURNS
 *  void
 *****************************************************************************/
void mmi_phb_mark_several_send_mms_insert_more_ind(U32 req_id)
{
    /*----------------------------------------------------------------*/
    /* Local Variables                                                */
    /*----------------------------------------------------------------*/
    MYQUEUE Message;
    mms_multi_object_insert_continue_ind_struct *local_buffer;
    peer_buff_struct *peer_buffer;
    U16 start_index, end_index;
    U8 *peer_pdu;
    U16 peer_pdu_len;
    
    /*----------------------------------------------------------------*/
    /* Code Body                                                      */
    /*----------------------------------------------------------------*/
    local_buffer = (mms_multi_object_insert_continue_ind_struct*) OslConstructDataPtr(sizeof(mms_multi_object_insert_continue_ind_struct));

    local_buffer->request_id = req_id;
    local_buffer->is_aborted = MMI_FALSE;
    
    start_index = g_mmi_phb_op_cntx.active_index;
    end_index = start_index +  MAX_MMS_OBJECT;
    if (end_index  < g_mmi_phb_op_cntx.total_count)
    {
        local_buffer->more = MMI_TRUE;
    }
    else
    {
        local_buffer->more = MMI_FALSE;
        end_index = g_mmi_phb_op_cntx.total_count;
    }
    local_buffer->num_of_object = end_index - start_index;
    g_mmi_phb_op_cntx.active_index = end_index;

    peer_pdu_len = local_buffer->num_of_object * sizeof(mms_multi_object_struct);
    peer_buffer = construct_peer_buff(peer_pdu_len, 0, 0, TD_CTRL);
    peer_pdu = (U8*) get_pdu_ptr(peer_buffer, &peer_pdu_len);

    mmi_phb_mark_several_send_mms_prepare_buffer(
            start_index,
            end_index,
            peer_pdu);
    
    Message.oslSrcId = MOD_MMI;
    Message.oslDestId = mms_get_service_module(MSG_ID_MMS_MULTI_OBJECT_INSERT_CONTINUE_IND);

    Message.oslMsgId = MSG_ID_MMS_MULTI_OBJECT_INSERT_CONTINUE_IND;
    Message.oslDataPtr = (oslParaType*) local_buffer;
    Message.oslPeerBuffPtr = (peer_buff_struct*)peer_buffer;
    SetProtocolEventHandler(mmi_phb_mark_several_send_mms_rsp, MSG_ID_MMS_MULTI_OBJECT_INSERT_CONTINUE_RES);
    OslMsgSendExtQueue(&Message);
}


/*****************************************************************************
 * FUNCTION
 *  mmi_phb_mark_several_send_mms_pre_req
 * DESCRIPTION
 *  Highlight handler for "send message" in PHB -> mark several -> Option
 * PARAMETERS
 *  void
 * RETURNS
 *  void
 *****************************************************************************/
U16 mmi_phb_mark_several_send_mms_prepare_buffer(
        U16 start_index,
        U16 end_index,
        void *buffer)
{
    /*----------------------------------------------------------------*/
    /* Local Variables                                                */
    /*----------------------------------------------------------------*/
    U16 i;
    U16 j = 0;
    U8* ucs2_address;
    mms_multi_object_struct *peer_buffer;
    U16 type;

    /*----------------------------------------------------------------*/
    /* Code Body                                                      */
    /*----------------------------------------------------------------*/
    peer_buffer = (mms_multi_object_struct*)buffer;
    for(i = start_index; i < end_index; i++)
    {
        ucs2_address = mmi_phb_mark_several_get_address_callback(i, &type);
        peer_buffer[j].type = (U32)type;
        mmi_ucs2_to_asc((S8*)(peer_buffer[j++].object), (S8*)ucs2_address);
    }
    return end_index;
}


/*****************************************************************************
 * FUNCTION
 *  mmi_phb_mark_several_send_mms_choose_address_more
 * DESCRIPTION
 *  Highlight handler for "send message" in PHB -> mark several -> Option
 * PARAMETERS
 *  void
 * RETURNS
 *  void
 *****************************************************************************/
void mmi_phb_mark_several_send_mms_choose_address_more(void)
{
    /*----------------------------------------------------------------*/
    /* Local Variables                                                */
    /*----------------------------------------------------------------*/

    /*----------------------------------------------------------------*/
    /* Code Body                                                      */
    /*----------------------------------------------------------------*/
    g_mmi_phb_list_p->mark_field[g_mmi_phb_op_cntx.active_index++] = g_mmi_phb_choose_field.number_type[g_mmi_phb_choose_field.highlight_index];
    mmi_frm_display_dummy_screen();
    mmi_frm_scrn_close(GRP_ID_PHB_MARK_SEVERAL, SCR_CHOOSE_NUMBER);

    if (g_mmi_phb_op_cntx.active_index < g_mmi_phb_op_cntx.total_count)
    {
        mmi_phb_entry_mark_several_send_mms_choose_address();
    }
    else
    {
        mmi_phb_mark_several_send_mms_req();
    }
}


/*****************************************************************************
 * FUNCTION
 *  mmi_phb_entry_mark_several_send_mms_choose_address
 * DESCRIPTION
 *  Highlight handler for "send message" in PHB -> mark several -> Option
 * PARAMETERS
 *  void
 * RETURNS
 *  void
 *****************************************************************************/
void mmi_phb_entry_mark_several_send_mms_choose_address(void)
{
    /*----------------------------------------------------------------*/
    /* Local Variables                                                */
    /*----------------------------------------------------------------*/

    /*----------------------------------------------------------------*/
    /* Code Body                                                      */
    /*----------------------------------------------------------------*/
    mmi_phb_entry_choose_field(
        g_mmi_phb_list_p->sg_id,
        g_mmi_phb_list_p->mark_array[g_mmi_phb_op_cntx.active_index],
        SRV_PHB_ENTRY_FIELD_MMS_PHB,
        mmi_phb_entry_mark_several_send_mms_choose_address,
        mmi_phb_mark_several_send_mms_choose_address_more,
        mmi_phb_mark_several_send_message_go_back_histoty,
        NULL,
        MMI_FALSE,
        MMI_TRUE);
}


/*****************************************************************************
 * FUNCTION
 *  mmi_phb_entry_mark_several_send_mms
 * DESCRIPTION
 *  Highlight handler for "send message" in PHB -> mark several -> Option
 * PARAMETERS
 *  void
 * RETURNS
 *  void
 *****************************************************************************/
void mmi_phb_mark_several_send_mms_choose_address(MMI_ID group_id)
{
    /*----------------------------------------------------------------*/
    /* Local Variables                                                */
    /*----------------------------------------------------------------*/

    /*----------------------------------------------------------------*/
    /* Code Body                                                      */
    /*----------------------------------------------------------------*/
    if (g_mmi_phb_op_cntx.total_count)
    {
        g_mmi_phb_op_cntx.active_index = 0;
        mmi_phb_entry_mark_several_send_mms_choose_address();
    }
    else
    {
        mmi_popup_display(
            (WCHAR *)GetString(STR_SMS_NUM_CANNOT_BE_EMPTY),
            MMI_EVENT_FAILURE,
            NULL);
        
        mmi_frm_group_close(GRP_ID_PHB_MARK_SEVERAL);        
    }
}


/*****************************************************************************
 * FUNCTION
 *  mmi_phb_pre_entry_mark_several_send_mms
 * DESCRIPTION
 *  Highlight handler for "send message" in PHB -> mark several -> Option
 * PARAMETERS
 *  void
 * RETURNS
 *  void
 *****************************************************************************/
void mmi_phb_pre_entry_mark_several_send_mms(void)
{
    /*----------------------------------------------------------------*/
    /* Local Variables                                                */
    /*----------------------------------------------------------------*/
    U16 max_count;

    /*----------------------------------------------------------------*/
    /* Code Body                                                      */
    /*----------------------------------------------------------------*/
    if (IsMessagesReEntering())
    {
        mmi_popup_display(
            (WCHAR *)GetString(STR_GLOBAL_NOT_AVAILABLE),
            MMI_EVENT_FAILURE,
            NULL);

        mmi_frm_group_close(GRP_ID_PHB_MARK_SEVERAL);
    }
    else
    {
        max_count = wap_custom_get_max_mms_address();
        if (mmi_phb_mark_several_filter_for_send_message(max_count, SRV_PHB_ENTRY_FIELD_MMS_PHB))
        {
            mmi_phb_continue_send_multi_message_confirm(
                max_count,
                mmi_phb_mark_several_send_mms_choose_address,
                mmi_phb_mark_several_send_message_go_back_histoty_ext,
                GRP_ID_PHB_MARK_SEVERAL);
        }
        else
        {
            mmi_phb_mark_several_send_mms_choose_address(GRP_ID_PHB_MARK_SEVERAL);
        }
    }
}


/*****************************************************************************
 * FUNCTION
 *  mmi_phb_highlight_mark_several_send_mms
 * DESCRIPTION
 *  Highlight handler for "send message" in PHB -> mark several -> Option
 * PARAMETERS
 *  void
 * RETURNS
 *  void
 *****************************************************************************/
void mmi_phb_highlight_mark_several_send_mms(void)
{
    /*----------------------------------------------------------------*/
    /* Local Variables                                                */
    /*----------------------------------------------------------------*/

    /*----------------------------------------------------------------*/
    /* Code Body                                                      */
    /*----------------------------------------------------------------*/
    ChangeLeftSoftkey(STR_GLOBAL_OK, IMG_GLOBAL_OK);
    ChangeRightSoftkey(STR_GLOBAL_BACK, IMG_GLOBAL_BACK);
    
    SetLeftSoftkeyFunction(mmi_phb_pre_entry_mark_several_send_mms, KEY_EVENT_UP);
    SetRightSoftkeyFunction(mmi_frm_scrn_close_active_id, KEY_EVENT_UP);
}

#endif /* defined(OBIGO_Q03C_MMS_V02) &&  defined(__MMI_MMS__) */
#endif /* __MMI_UNIFIED_COMPOSER__ */
#endif /*__MMI_PHB_SEND_MSG__ */


#ifdef __MMI_FTE_SUPPORT__
/*****************************************************************************
 * FUNCTION
 *  mmi_phb_fte_contact_list_tap_callback
 * DESCRIPTION
 *  fte contact main list tap callback
 * PARAMETERS
 *  void
 * RETURNS
 *  void
 *****************************************************************************/
static void mmi_phb_fte_mark_list_tap_callback(mmi_tap_type_enum tap_type, S32 index)
{
    /*----------------------------------------------------------------*/
    /* Local Variables                                                */
    /*----------------------------------------------------------------*/

    /*----------------------------------------------------------------*/
    /* Code Body                                                      */
    /*----------------------------------------------------------------*/
    mmi_phb_mark_several_check();
}
#endif /* __MMI_FTE_SUPPORT__ */


/*****************************************************************************
 * FUNCTION
 *  mmi_phb_op_mark_several_move_pre_req
 * DESCRIPTION
 *  move several interfce
 * PARAMETERS
 *  void
 * RETURNS
 *  void
 *****************************************************************************/
void mmi_phb_op_mark_several_move_pre_req(MMI_ID group_id)
{
    /*----------------------------------------------------------------*/
    /* Local Variables                                                */
    /*----------------------------------------------------------------*/
    
    /*----------------------------------------------------------------*/
    /* Code Body                                                      */
    /*----------------------------------------------------------------*/
    g_phb_cntx_mgr.processing = MMI_TRUE;
    g_phb_cntx_mgr.state = MMI_PHB_STATE_COPY_MULTI;
    
    g_mmi_phb_op_cntx.canceled = MMI_FALSE;
    g_mmi_phb_op_cntx.action = MMI_PHB_OP_MULTI_MOVE;
    g_mmi_phb_op_cntx.state = MMI_PHB_STATE_COPY_MULTI;
    g_mmi_phb_op_cntx.sg_id = group_id;

    mmi_frm_scrn_close(group_id, SCR_ID_PHB_MOVE_SEVERAL);

    mmi_phb_show_mass_processing(
        g_mmi_phb_op_cntx.sg_id,
        STR_GLOBAL_MOVING,
        g_mmi_phb_list_p->mark_count);
    
    MMI_TRACE(MMI_PHB_TRACE_GROUP, TRC_MMI_PHB_OP_MOVE_ALL_PRE_REQ, g_mmi_phb_op_cntx.dst_storage, g_mmi_phb_op_cntx.total_count);

    srv_phb_oplib_move_several_contact(
        g_mmi_phb_list_p->mark_array,
        g_mmi_phb_list_p->mark_count,
        g_mmi_phb_op_cntx.dst_storage,
        mmi_phb_op_mark_several_cb,
        &g_mmi_phb_op_cntx);
}


/*****************************************************************************
 * FUNCTION
 *  mmi_phb_op_mark_several_move_coinfirm
 * DESCRIPTION
 *  confirm mark several move
 * PARAMETERS
 *  void
 * RETURNS
 *  void
 *****************************************************************************/
void mmi_phb_op_mark_several_move_coinfirm(MMI_ID group_id)
{
    /*----------------------------------------------------------------*/
    /* Local Variables                                                */
    /*----------------------------------------------------------------*/
    mmi_confirm_property_struct arg;

    /*----------------------------------------------------------------*/
    /* Code Body                                                      */
    /*----------------------------------------------------------------*/
    if (mmi_phb_op_all_check_storage_status(g_mmi_phb_op_cntx.src_storage, MMI_PHB_CHECK_STORAGE_EMPTY, MMI_TRUE, group_id)
        || mmi_phb_op_all_check_storage_status(g_mmi_phb_op_cntx.dst_storage, MMI_PHB_CHECK_STORAGE_FULL, MMI_TRUE, group_id))
    {
        return;
    }

    mmi_confirm_property_init(&arg, CNFM_TYPE_YESNO);
    arg.parent_id = group_id;
    arg.callback = (mmi_proc_func)mmi_phb_comfirm_proc;
        
    mmi_phb_confirm_user_data_init(&g_mmi_phb_confirm_user_data);
    g_mmi_phb_confirm_user_data.sg_id = group_id;
    g_mmi_phb_confirm_user_data.LSK_function = mmi_phb_op_mark_several_move_pre_req;
        
    arg.user_tag = (void *)&g_mmi_phb_confirm_user_data;
        
    mmi_confirm_display(
        (WCHAR *) get_string(STR_ID_PHB_MULTI_OP_MOVE_SELECTED_ASK),
        MMI_EVENT_QUERY,
        &arg);
}


/*****************************************************************************
 * FUNCTION
 *  mmi_phb_op_mark_several_copy_pre_req
 * DESCRIPTION
 *  copy several interfce
 * PARAMETERS
 *  void
 * RETURNS
 *  void
 *****************************************************************************/
void mmi_phb_op_mark_several_copy_pre_req(MMI_ID group_id)
{
    /*----------------------------------------------------------------*/
    /* Local Variables                                                */
    /*----------------------------------------------------------------*/
    
    /*----------------------------------------------------------------*/
    /* Code Body                                                      */
    /*----------------------------------------------------------------*/
    g_phb_cntx_mgr.processing = MMI_TRUE;
    g_phb_cntx_mgr.state = MMI_PHB_STATE_COPY_MULTI;
    
    g_mmi_phb_op_cntx.canceled = MMI_FALSE;
    g_mmi_phb_op_cntx.action = MMI_PHB_OP_MULTI_COPY;
    g_mmi_phb_op_cntx.state = MMI_PHB_STATE_COPY_MULTI;
    g_mmi_phb_op_cntx.sg_id = group_id;

    mmi_phb_show_mass_processing(
        g_mmi_phb_op_cntx.sg_id,
        STR_GLOBAL_COPYING,
        g_mmi_phb_list_p->mark_count);
   
    srv_phb_oplib_copy_several_contact(
        g_mmi_phb_list_p->mark_array,
        g_mmi_phb_list_p->mark_count,
        g_mmi_phb_op_cntx.dst_storage,
        mmi_phb_op_mark_several_cb,
        &g_mmi_phb_op_cntx);
}


/*****************************************************************************
 * FUNCTION
 *  mmi_phb_op_mark_several_copy_coinfirm
 * DESCRIPTION
 *  confirm mark several copy
 * PARAMETERS
 *  void
 * RETURNS
 *  void
 *****************************************************************************/
void mmi_phb_op_mark_several_copy_coinfirm(MMI_ID group_id)
{
    /*----------------------------------------------------------------*/
    /* Local Variables                                                */
    /*----------------------------------------------------------------*/
    mmi_confirm_property_struct arg;

    /*----------------------------------------------------------------*/
    /* Code Body                                                      */
    /*----------------------------------------------------------------*/
    if (mmi_phb_op_all_check_storage_status(g_mmi_phb_op_cntx.src_storage, MMI_PHB_CHECK_STORAGE_EMPTY, MMI_TRUE, group_id)
        || mmi_phb_op_all_check_storage_status(g_mmi_phb_op_cntx.dst_storage, MMI_PHB_CHECK_STORAGE_FULL, MMI_TRUE, group_id))
    {
        return;
    }

    mmi_confirm_property_init(&arg, CNFM_TYPE_YESNO);
    arg.parent_id = group_id;
    arg.callback = (mmi_proc_func)mmi_phb_comfirm_proc;
        
    mmi_phb_confirm_user_data_init(&g_mmi_phb_confirm_user_data);
    g_mmi_phb_confirm_user_data.sg_id = group_id;
    g_mmi_phb_confirm_user_data.LSK_function = mmi_phb_op_mark_several_copy_pre_req;
        
    arg.user_tag = (void *)&g_mmi_phb_confirm_user_data;
        
    mmi_confirm_display(
        (WCHAR *) get_string(STR_ID_PHB_MULTI_OP_COPY_SELECTED_ASK),
        MMI_EVENT_QUERY,
        &arg);
}


/*****************************************************************************
 * FUNCTION
 *  mmi_phb_highlight_mark_several_copy
 * DESCRIPTION
 *  Highlight handler for "copy" in PHB -> mark several -> Option
 * PARAMETERS
 *  void
 * RETURNS
 *  void
 *****************************************************************************/
void mmi_phb_highlight_mark_several_copy(void)
{
    /*----------------------------------------------------------------*/
    /* Local Variables                                                */
    /*----------------------------------------------------------------*/

    /*----------------------------------------------------------------*/
    /* Code Body                                                      */
    /*----------------------------------------------------------------*/
    //ChangeLeftSoftkey(STR_GLOBAL_OK, IMG_GLOBAL_OK);
    //ChangeRightSoftkey(STR_GLOBAL_BACK, IMG_GLOBAL_BACK);
    
    //SetLeftSoftkeyFunction(mmi_phb_op_mark_several_copy_coinfirm, KEY_EVENT_UP);
    //SetRightSoftkeyFunction(mmi_frm_scrn_close_active_id, KEY_EVENT_UP);
}


/*****************************************************************************
 * FUNCTION
 *  mmi_phb_op_mark_several_delete_pre_req
 * DESCRIPTION
 *  delete several interfce
 * PARAMETERS
 *  void
 * RETURNS
 *  void
 *****************************************************************************/
void mmi_phb_op_mark_several_delete_pre_req(MMI_ID group_id)
{
    /*----------------------------------------------------------------*/
    /* Local Variables                                                */
    /*----------------------------------------------------------------*/

    /*----------------------------------------------------------------*/
    /* Code Body                                                      */
    /*----------------------------------------------------------------*/
    g_phb_cntx_mgr.processing = MMI_TRUE;
    g_phb_cntx_mgr.state = MMI_PHB_STATE_DELETE_MULTI;
    
    g_mmi_phb_op_cntx.canceled = MMI_FALSE;
    g_mmi_phb_op_cntx.action = MMI_PHB_OP_MULTI_DELETE;
    g_mmi_phb_op_cntx.state = MMI_PHB_STATE_DELETE_MULTI;
    g_mmi_phb_op_cntx.sg_id = group_id;

    mmi_phb_show_mass_processing(
        g_mmi_phb_op_cntx.sg_id,
        STR_GLOBAL_DELETING,
        g_mmi_phb_list_p->mark_count);
    
    srv_phb_oplib_delete_several_contact(
        g_mmi_phb_list_p->mark_array,
        g_mmi_phb_list_p->mark_count,
        mmi_phb_op_mark_several_cb,
        &g_mmi_phb_op_cntx);
}

/*****************************************************************************
 * FUNCTION
 *  mmi_phb_op_mark_several_delete_coinfirm
 * DESCRIPTION
 *  confirm mark several delete
 * PARAMETERS
 *  void
 * RETURNS
 *  void
 *****************************************************************************/
void mmi_phb_op_mark_several_delete_coinfirm(MMI_ID group_id)
{
    /*----------------------------------------------------------------*/
    /* Local Variables                                                                                          */
    /*----------------------------------------------------------------*/
    mmi_confirm_property_struct arg;

    /*----------------------------------------------------------------*/
    /* Code Body                                                      */
    /*----------------------------------------------------------------*/
    mmi_confirm_property_init(&arg, CNFM_TYPE_YESNO);
    arg.parent_id = group_id;
    arg.callback = (mmi_proc_func)mmi_phb_comfirm_proc;
    arg.f_auto_map_empty_softkey = MMI_FALSE;
        
    mmi_phb_confirm_user_data_init(&g_mmi_phb_confirm_user_data);
    g_mmi_phb_confirm_user_data.sg_id = group_id;
    g_mmi_phb_confirm_user_data.LSK_function = mmi_phb_op_mark_several_delete_pre_req;
        
    arg.user_tag = (void *)&g_mmi_phb_confirm_user_data;
        
    mmi_confirm_display(
        (WCHAR *) get_string(STR_ID_PHB_MULTI_OP_DELETE_SELECTED_ASK),
        MMI_EVENT_QUERY,
        &arg);
}


/*****************************************************************************
 * FUNCTION
 *  mmi_phb_highlight_mark_several_delete
 * DESCRIPTION
 *  Highlight handler for "delete" in PHB -> mark several -> Option
 * PARAMETERS
 *  void
 * RETURNS
 *  void
 *****************************************************************************/
void mmi_phb_highlight_mark_several_delete(void)
{
    /*----------------------------------------------------------------*/
    /* Local Variables                                                */
    /*----------------------------------------------------------------*/

    /*----------------------------------------------------------------*/
    /* Code Body                                                      */
    /*----------------------------------------------------------------*/
    //ChangeLeftSoftkey(STR_GLOBAL_OK, IMG_GLOBAL_OK);
    //ChangeRightSoftkey(STR_GLOBAL_BACK, IMG_GLOBAL_BACK);

    //SetLeftSoftkeyFunction(mmi_phb_op_mark_several_delete_coinfirm, KEY_EVENT_UP);
    //SetRightSoftkeyFunction(mmi_frm_scrn_close_active_id, KEY_EVENT_UP);
}


/*****************************************************************************
 * FUNCTION
 *  mmi_phb_op_mark_several_unmark_all
 * DESCRIPTION
 *  Unmark All entry in list
 * PARAMETERS
 *  void
 * RETURNS
 *  void
 *****************************************************************************/
void mmi_phb_op_mark_several_unmark_all(void)
{
    /*----------------------------------------------------------------*/
    /* Local Variables                                                */
    /*----------------------------------------------------------------*/
    U16 index = 0;

    /*----------------------------------------------------------------*/
    /* Code Body                                                      */
    /*----------------------------------------------------------------*/    
    for(index = 0; index < g_mmi_phb_list_p->contact_count; index++)
    {
        if (mmi_phb_bitmask_get_state(g_mmi_phb_list_p->bitmask, g_mmi_phb_list_p->contact_array[index]))
        {
            mmi_phb_bitmask_set_state(g_mmi_phb_list_p->bitmask, g_mmi_phb_list_p->contact_array[index], MMI_FALSE);
        }            
    }
    
    mmi_frm_scrn_close_active_id();
}


/*****************************************************************************
 * FUNCTION
 *  mmi_phb_highlight_mark_several_unmark_all
 * DESCRIPTION
 *  Highlight handler for "unmark all" in PHB -> mark several -> Option
 * PARAMETERS
 *  void
 * RETURNS
 *  void
 *****************************************************************************/
void mmi_phb_highlight_mark_several_unmark_all(void)
{
    /*----------------------------------------------------------------*/
    /* Local Variables                                                */
    /*----------------------------------------------------------------*/

    /*----------------------------------------------------------------*/
    /* Code Body                                                      */
    /*----------------------------------------------------------------*/
    MMI_TRACE(MMI_PHB_TRACE_GROUP, TRC_MMI_PHB_HIGHLIGHT_MULTI_OP_COPY_SELECTED);

    ChangeLeftSoftkey(STR_GLOBAL_OK, IMG_GLOBAL_OK);
    ChangeRightSoftkey(STR_GLOBAL_BACK, IMG_GLOBAL_BACK);

    SetLeftSoftkeyFunction(mmi_phb_op_mark_several_unmark_all, KEY_EVENT_UP);
    SetRightSoftkeyFunction(mmi_frm_scrn_close_active_id, KEY_EVENT_UP);
}


/*****************************************************************************
 * FUNCTION
 *  mmi_phb_op_mark_several_mark_all
 * DESCRIPTION
 *  mark All entry in list
 * PARAMETERS
 *  void
 * RETURNS
 *  void
 *****************************************************************************/
void mmi_phb_op_mark_several_mark_all(void)
{
    /*----------------------------------------------------------------*/
    /* Local Variables                                                */
    /*----------------------------------------------------------------*/
    U16 index = 0;

    /*----------------------------------------------------------------*/
    /* Code Body                                                      */
    /*----------------------------------------------------------------*/    
    for(index = 0; index < g_mmi_phb_list_p->contact_count; index++)
    {
        if (!mmi_phb_bitmask_get_state(g_mmi_phb_list_p->bitmask, g_mmi_phb_list_p->contact_array[index]))
        {
            mmi_phb_bitmask_set_state(g_mmi_phb_list_p->bitmask, g_mmi_phb_list_p->contact_array[index], MMI_TRUE);
        }            
    }
    
    mmi_frm_scrn_close_active_id();
}


/*****************************************************************************
 * FUNCTION
 *  mmi_phb_highlight_mark_several_mark_all
 * DESCRIPTION
 *  Highlight handler for "mark All" in PHB -> mark several -> Option
 * PARAMETERS
 *  void
 * RETURNS
 *  void
 *****************************************************************************/
void mmi_phb_highlight_mark_several_mark_all(void)
{
    /*----------------------------------------------------------------*/
    /* Local Variables                                                */
    /*----------------------------------------------------------------*/

    /*----------------------------------------------------------------*/
    /* Code Body                                                      */
    /*----------------------------------------------------------------*/
    MMI_TRACE(MMI_PHB_TRACE_GROUP, TRC_MMI_PHB_HIGHLIGHT_MULTI_OP_UNSELECT_ALL_FROM_PHONE); 

    ChangeLeftSoftkey(STR_GLOBAL_OK, IMG_GLOBAL_OK);
    ChangeRightSoftkey(STR_GLOBAL_BACK, IMG_GLOBAL_BACK);

    SetLeftSoftkeyFunction(mmi_phb_op_mark_several_mark_all, KEY_EVENT_UP);
    SetRightSoftkeyFunction(mmi_frm_scrn_close_active_id, KEY_EVENT_UP);
}


/*****************************************************************************
 * FUNCTION
 *  mmi_phb_op_mark_several_mark_unmark
 * DESCRIPTION
 *  mark or unmark a entry in list
 * PARAMETERS
 *  void
 * RETURNS
 *  void
 *****************************************************************************/
void mmi_phb_op_mark_several_mark_unmark(void)
{
    /*----------------------------------------------------------------*/
    /* Local Variables                                                */
    /*----------------------------------------------------------------*/

    /*----------------------------------------------------------------*/
    /* Code Body                                                      */
    /*----------------------------------------------------------------*/    
    mmi_phb_mark_several_check();

    mmi_frm_scrn_close_active_id();
}


/*****************************************************************************
 * FUNCTION
 *  mmi_phb_highlight_mark_several_mark_unmark
 * DESCRIPTION
 *  Highlight handler for "mark" and "unmark" in PHB -> mark several -> Option
 * PARAMETERS
 *  void
 * RETURNS
 *  void
 *****************************************************************************/
void mmi_phb_highlight_mark_several_mark_unmark(void)
{
    /*----------------------------------------------------------------*/
    /* Local Variables                                                */
    /*----------------------------------------------------------------*/

    /*----------------------------------------------------------------*/
    /* Code Body                                                      */
    /*----------------------------------------------------------------*/
    MMI_TRACE(MMI_PHB_TRACE_GROUP, TRC_MMI_PHB_HIGHLIGHT_MULTI_OP_SELECT_ALL);

    ChangeLeftSoftkey(STR_GLOBAL_OK, IMG_GLOBAL_OK);
    ChangeRightSoftkey(STR_GLOBAL_BACK, IMG_GLOBAL_BACK);

    SetLeftSoftkeyFunction(mmi_phb_op_mark_several_mark_unmark, KEY_EVENT_UP);
    SetRightSoftkeyFunction(mmi_frm_scrn_close_active_id, KEY_EVENT_UP);
}


mmi_ret mmi_phb_mark_several_menu_cui_proc(mmi_event_struct *evt)
{
    /*----------------------------------------------------------------*/
    /* Local Variables                                                                                  */
    /*----------------------------------------------------------------*/
	
    /*----------------------------------------------------------------*/
    /* Code Body                                                                                       */
    /*----------------------------------------------------------------*/

    switch (evt->evt_id)
    {
        case EVT_ID_CUI_MENU_LIST_ENTRY:
        {
            cui_menu_event_struct *menu_evt = (cui_menu_event_struct*)evt;
            return MMI_RET_OK;
            break;
        }

        case EVT_ID_CUI_MENU_ITEM_SELECT:
        {
            cui_menu_event_struct *menu_evt = (cui_menu_event_struct*)evt;
            if (menu_evt->highlighted_menu_id == MENU_ID_PHB_MARK_SEVERAL_OP_MARK_ALL)
            {
                mmi_phb_op_mark_several_mark_all();
            }
            else if (menu_evt->highlighted_menu_id == MENU_ID_PHB_MARK_SEVERAL_OP_UNMARK_ALL)
            {
                mmi_phb_op_mark_several_unmark_all();
            }
            else if (menu_evt->highlighted_menu_id == MENU_ID_PHB_MARK_SEVERAL_OP_MARK)
            {
                mmi_phb_op_mark_several_mark_unmark();
            }
            else if (menu_evt->highlighted_menu_id == MENU_ID_PHB_MARK_SEVERAL_OP_UNMARK)
            {
                mmi_phb_op_mark_several_mark_unmark();
            }
        #ifdef __MMI_PHB_SEND_MSG__
        #ifdef __MMI_UNIFIED_COMPOSER__
            else if (menu_evt->highlighted_menu_id == MENU_ID_PHB_MARK_SEVERAL_OP_SEND_MESSAGE)
            {
                mmi_phb_pre_entry_mark_several_send_uc();
            }
        #else /* __MMI_UNIFIED_COMPOSER__ */
            else if (menu_evt->highlighted_menu_id == MENU_ID_PHB_MARK_SEVERAL_OP_SEND_SMS)
            {
                mmi_phb_pre_entry_mark_several_send_sms();
            }
        #if defined(__MMI_MMS__) &&  defined(OBIGO_Q03C_MMS_V02) && !defined(__MMI_SLIM_MMS_2__)
            else if (menu_evt->highlighted_menu_id == MENU_ID_PHB_MARK_SEVERAL_OP_SEND_MMS)
            {
                mmi_phb_pre_entry_mark_several_send_mms();
            }
        #endif /* defined(OBIGO_Q03C_MMS_V02) &&  defined(__MMI_MMS__) */
        #endif /* __MMI_UNIFIED_COMPOSER__ */
        #endif /* __MMI_PHB_SEND_MSG__ */
        #ifdef __MMI_UDX_VCARD_SUPPORT__
            else if (menu_evt->highlighted_menu_id == MENU_ID_PHB_MARK_SEVERAL_OP_BUILD_UDX)
            {
                mmi_phb_mark_several_op_build_udx_confirm(g_mmi_phb_list_p->sg_id);
            }
        #endif
        #if defined(__MMI_VCARD__) && defined(__MMI_OPP_SUPPORT__)
            else if (menu_evt->highlighted_menu_id == MENU_ID_PHB_MARK_SEVERAL_OP_SEND_VCARD)
            {
                mmi_phb_mark_several_op_sned_vcard(g_mmi_phb_list_p->sg_id);
            }
        #endif
            else if (menu_evt->highlighted_menu_id == MENU_ID_PHB_MARK_SEVERAL_OP_DELETE_SELECTED)
            {
                mmi_phb_op_mark_several_delete_coinfirm(g_mmi_phb_list_p->sg_id);
            }
            else if (menu_evt->highlighted_menu_id == MENU_ID_PHB_MARK_SEVERAL_OP_COPY_SELECTED)
            {
                mmi_phb_op_mark_several_copy_coinfirm(g_mmi_phb_list_p->sg_id);
            }
            else if (menu_evt->highlighted_menu_id == MENU_ID_PHB_MARK_SEVERAL_OP_MOVE_SELECTED)
            {
                mmi_phb_op_mark_several_move_coinfirm(g_mmi_phb_list_p->sg_id);
            }
            else
            {
                return MMI_RET_DONT_CARE;
            }
            return MMI_RET_OK;
            break;
        }
        
        case EVT_ID_CUI_MENU_CLOSE_REQUEST:
        {
            cui_menu_event_struct *menu_evt = (cui_menu_event_struct*)evt;
            cui_menu_close(menu_evt->sender_id);
            return MMI_RET_OK;
            break;
        }
        
        default:
            return MMI_RET_DONT_CARE;
            break;
    }
}


/*****************************************************************************
 * FUNCTION
 *  mmi_phb_entry_mark_several_option
 * DESCRIPTION
 *  Entry mark several Options menu
 * PARAMETERS
 *  void
 * RETURNS
 *  the description of return value, if any.(?)
 *****************************************************************************/
void mmi_phb_entry_mark_several_option(void)
{
    /*----------------------------------------------------------------*/
    /* Local Variables                                                */
    /*----------------------------------------------------------------*/
    mmi_id menu_gid;

    /*----------------------------------------------------------------*/
    /* Code Body                                                      */
    /*----------------------------------------------------------------*/
    mmi_phb_mark_several_populate();

    menu_gid = cui_menu_create(
               GRP_ID_PHB_MARK_SEVERAL,
               CUI_MENU_SRC_TYPE_RESOURCE,
               CUI_MENU_TYPE_OPTION,
               MENU_ID_PHB_MARK_SEVERAL_OP,
               MMI_FALSE, NULL);

    if (mmi_phb_bitmask_get_state(g_mmi_phb_list_p->bitmask, g_mmi_phb_list_p->store_index))
    {
        cui_menu_set_item_hidden(menu_gid, MENU_ID_PHB_MARK_SEVERAL_OP_MARK, MMI_TRUE);
        cui_menu_set_item_hidden(menu_gid, MENU_ID_PHB_MARK_SEVERAL_OP_UNMARK, MMI_FALSE);
    }
    else
    {
        cui_menu_set_item_hidden(menu_gid, MENU_ID_PHB_MARK_SEVERAL_OP_MARK, MMI_FALSE);
        cui_menu_set_item_hidden(menu_gid, MENU_ID_PHB_MARK_SEVERAL_OP_UNMARK, MMI_TRUE);
    } 
    
    #ifdef __MMI_PHB_SEND_MSG__
    #ifdef __MMI_UNIFIED_COMPOSER__
        cui_menu_set_item_hidden(menu_gid, MENU_ID_PHB_MARK_SEVERAL_OP_SEND_MESSAGE, MMI_TRUE);
    #else
        cui_menu_set_item_hidden(menu_gid, MENU_ID_PHB_MARK_SEVERAL_OP_SEND_SMS, MMI_TRUE);
    #if defined(__MMI_MMS__) &&  defined(OBIGO_Q03C_MMS_V02) && !defined(__MMI_SLIM_MMS_2__)
        cui_menu_set_item_hidden(menu_gid, MENU_ID_PHB_MARK_SEVERAL_OP_SEND_MMS, MMI_TRUE);
    #endif /* defined(OBIGO_Q03C_MMS_V02) &&  defined(__MMI_MMS__) */
    #endif /* __MMI_UNIFIED_COMPOSER__ */
    #endif /*__MMI_PHB_SEND_MSG__ */

    cui_menu_set_item_hidden(menu_gid, MENU_ID_PHB_MARK_SEVERAL_OP_DELETE_SELECTED, MMI_TRUE);
    cui_menu_set_item_hidden(menu_gid, MENU_ID_PHB_MARK_SEVERAL_OP_COPY_SELECTED, MMI_TRUE);
    cui_menu_set_item_hidden(menu_gid, MENU_ID_PHB_MARK_SEVERAL_OP_MOVE_SELECTED, MMI_TRUE);
#ifdef __MMI_UDX_VCARD_SUPPORT__
    cui_menu_set_item_hidden(menu_gid, MENU_ID_PHB_MARK_SEVERAL_OP_BUILD_UDX, MMI_TRUE);
#endif
#if defined(__MMI_VCARD__) && defined(__MMI_OPP_SUPPORT__)
    cui_menu_set_item_hidden(menu_gid, MENU_ID_PHB_MARK_SEVERAL_OP_SEND_VCARD, MMI_TRUE);
#endif

    cui_menu_set_item_hidden(menu_gid, MENU_ID_PHB_MARK_SEVERAL_OP_MARK_ALL, MMI_FALSE);
    cui_menu_set_item_hidden(menu_gid, MENU_ID_PHB_MARK_SEVERAL_OP_UNMARK_ALL, MMI_FALSE);
    
    if (mmi_phb_mark_several_search_count() == 0)
    {
        cui_menu_set_item_hidden(menu_gid, MENU_ID_PHB_MARK_SEVERAL_OP_UNMARK_ALL, MMI_TRUE);
    }
    else if (mmi_phb_mark_several_search_count() == g_mmi_phb_list_p->contact_count)
    {
        cui_menu_set_item_hidden(menu_gid, MENU_ID_PHB_MARK_SEVERAL_OP_MARK_ALL, MMI_TRUE);
    }

    g_mmi_phb_mark_several_build_op_func(menu_gid);

    cui_menu_set_default_title_image(menu_gid, (UI_image_type)GetImage(IMG_SCR_PBOOK_CAPTION));

    cui_menu_run(menu_gid);
}



static void mmi_phb_exit_mark_serveral_list(void)
{
    /*----------------------------------------------------------------*/
    /* Local Variables                                                */
    /*----------------------------------------------------------------*/

    /*----------------------------------------------------------------*/
    /* Code Body                                                      */
    /*----------------------------------------------------------------*/
#if defined(__MMI_INTELLIGENT_CALL_ALERT__)
    mmi_phb_speak_name_end();
#endif /* defined(__MMI_INTELLIGENT_CALL_ALERT__) */

#if defined(__MMI_PHB_QUICK_SEARCH__)
    mmi_imc_key_set_pre_key_handler(NULL);
#endif
}


/*****************************************************************************
 * FUNCTION
 *  mmi_phb_mark_several_list
 * DESCRIPTION
 *  Entry fuction of mark several list
 * PARAMETERS
 *  void
 * RETURNS
 *  void
 *****************************************************************************/
void mmi_phb_entry_mark_several_list(
        U16 str_title,
        U16 img_title,
        U16 str_lsk,
        U16 img_lsk,
        U16 scr_id,
        FunctionPtr lsk_ptr,
        FunctionPtr csk_ptr,
        FunctionPtr entry_ptr)
{
    /*----------------------------------------------------------------*/
    /* Local Variables                                                */
    /*----------------------------------------------------------------*/
    U8 *gui_buffer;
    U16 entry_count;
    srv_phb_filter_struct *filter;
    U32 handle;
    mmi_phb_refresh_struct *refresh_data;

    /*----------------------------------------------------------------*/
    /* Code Body                                                      */
    /*----------------------------------------------------------------*/
    if (!mmi_phb_check_ready(MMI_TRUE))
    {
        return;
    }
    
    filter = mmi_phb_list_build_filter(
             g_mmi_phb_list_p->storage,
             SRV_PHB_ENTRY_FIELD_ALL,
             NULL,
             NULL,
             0);
    
    entry_count = (U16) srv_phb_oplib_build_contact_list(filter, g_mmi_phb_list_p->contact_array, MMI_PHB_ENTRIES);
    g_mmi_phb_list_p->contact_count = entry_count;
    
    mmi_phb_list_free_filter(filter);

    if (g_mmi_phb_list_p->contact_count == 0)
    {        
        mmi_popup_display_simple(
            (UI_string_type)GetString(STR_ID_PHB_NO_ENTRY_TO_SELECT),
            MMI_EVENT_FAILURE,
            g_mmi_phb_list_p->sg_id,
            NULL);

        return;
    }

    if (mmi_frm_scrn_enter(
            g_mmi_phb_list_p->sg_id,
            scr_id,
            mmi_phb_exit_mark_serveral_list,
            entry_ptr,
            MMI_FRM_FULL_SCRN))
    {
        gui_buffer = mmi_frm_scrn_get_active_gui_buf();
        
        RegisterHighlightHandler(mmi_phb_mark_several_highlight_hdlr);

    #ifdef __MMI_UI_HINTS_IN_MENUITEM__
        set_force_icon_on_highlight_only_in_menuitem();
    #endif

        EnableCenterSoftkey(0, IMG_ID_PHB_CSK_MARK);

        if (!mmi_is_redrawing_bk_screens())
        {
            handle = mmi_phb_cntx_mgr_get_handle_by_sg_id(mmi_phb_cntx_mgr_get_current_sg_id());
            refresh_data = mmi_phb_cntx_mgr_get_refresh_data(handle);

            if (refresh_data != NULL && refresh_data->refresh_type != MMI_PHB_OP_NONE)
            {
                gui_buffer = NULL;
            #if defined(__MMI_PHB_QUICK_SEARCH__)
                g_mmi_phb_list_p->qsearch_input_buffer[0] = 0;
            #endif

                g_mmi_phb_list_p->list_index = mmi_phb_calc_list_index(
                                                refresh_data,
                                                MMI_PHB_LIST_TYPE_MULTI_SELECT,
                                                g_mmi_phb_list_p->list_index,
                                                g_mmi_phb_list_p->contact_array,
                                                g_mmi_phb_list_p->bitmask,
                                                g_mmi_phb_list_p->contact_count);
                
                refresh_data->refresh_type = MMI_PHB_OP_NONE;
            }
        }
    #if defined(__MMI_PHB_QUICK_SEARCH__)

        RegisterCat200SearchFunction(mmi_phb_quick_search_find_entry);
        g_phb_quick_search_enter = MMI_PHB_QUICK_SEARCH_GENERIC;
        
        if (gui_buffer != NULL)
        {
            entry_count = (U16) mmi_phb_quick_search_find_entry((U8 *) g_mmi_phb_list_p->qsearch_input_buffer);
        }
        
        ShowCategory202Screen(
            str_title,
            img_title,
            str_lsk,
            img_lsk,
            STR_GLOBAL_BACK,
            IMG_GLOBAL_BACK,
            NULL,
            entry_count,
            mmi_phb_list_get_item,
            mmi_phb_list_get_hint_ext,
            mmi_phb_mark_several_get_state,
            mmi_phb_mark_several_set_state,
            g_mmi_phb_list_p->list_index,
            IMG_ID_PHB_QUICK_SEARCH_FIND,
            (U8*) g_mmi_phb_list_p->qsearch_input_buffer,
            MMI_PHB_QUICK_SEARCH_INPUT_LENGTH,
            gui_buffer);

        SetLeftSoftkeyFunction(lsk_ptr, KEY_EVENT_UP);
        SetCategory200LeftSoftkeyFunction(lsk_ptr, KEY_EVENT_UP);
        SetCategory200RightSoftkeyFunction(mmi_frm_scrn_close_active_id, KEY_EVENT_UP);
                
    #else
    
        ShowCategory384Screen(
            (UI_string_type)GetString(str_title),
            (PU8)GetImage(img_title),
            str_lsk,
            img_lsk,
            STR_GLOBAL_BACK,
            IMG_GLOBAL_BACK,
            NULL,
            g_mmi_phb_list_p->contact_count,
            mmi_phb_list_get_item,
            mmi_phb_list_get_hint_ext,
            mmi_phb_mark_several_get_state,
            mmi_phb_mark_several_set_state,
            g_mmi_phb_list_p->list_index,
            gui_buffer);
    
        SetLeftSoftkeyFunction(lsk_ptr, KEY_EVENT_UP);
        SetRightSoftkeyFunction(mmi_frm_scrn_close_active_id, KEY_EVENT_UP);
    #endif

    #ifdef __MMI_TOUCH_SCREEN__
        wgui_register_list_item_selected_callback_all(UI_dummy_function);
    #endif

        SetCenterSoftkeyFunction(csk_ptr, KEY_EVENT_UP);

        mmi_imc_key_set_pre_key_handler(mmi_phb_star_key_pre_handler);

    #ifdef __MMI_FTE_SUPPORT__
        wgui_register_tap_callback(mmi_phb_fte_mark_list_tap_callback);
    #endif
    }
}


/*****************************************************************************
 * FUNCTION
 *  mmi_phb_entry_mark_several_main
 * DESCRIPTION
 *  Entry fuction of mark several main
 * PARAMETERS
 *  void
 * RETURNS
 *  void
 *****************************************************************************/
void mmi_phb_entry_mark_several_main(void)
{
    /*----------------------------------------------------------------*/
    /* Local Variables                                                */
    /*----------------------------------------------------------------*/

    /*----------------------------------------------------------------*/
    /* Code Body                                                      */
    /*----------------------------------------------------------------*/
    g_mmi_phb_mark_several_build_op_func = mmi_phb_mark_several_main_build_option;

    mmi_phb_entry_mark_several_list(
        STR_SCR_PBOOK_VIEW_CAPTION,
        IMG_SCR_PBOOK_CAPTION,
        STR_GLOBAL_OPTIONS,
        IMG_GLOBAL_OPTIONS,
        SCR_ID_PHB_MULTI_OP_PHB_LIST,
        mmi_phb_entry_mark_several_option,
        mmi_phb_mark_several_check,
        mmi_phb_entry_mark_several_main);
}

/*****************************************************************************
 * FUNCTION
 *  mmi_phb_pre_entry_mark_several_main
 * DESCRIPTION
 *  pre Entry fuction of mark several main
 * PARAMETERS
 *  void
 * RETURNS
 *  void
 *****************************************************************************/
void mmi_phb_pre_entry_mark_several_main(MMI_ID group_id)
{
    /*----------------------------------------------------------------*/
    /* Local Variables                                                */
    /*----------------------------------------------------------------*/
    mmi_id sg_id = group_id;
    mmi_id new_sg_id;
    U32 handle;    
    mmi_phb_list_cntx_struct *list_cntx;
    mmi_phb_list_cntx_struct *parent_data;

    /*----------------------------------------------------------------*/
    /* Code Body                                                      */
    /*----------------------------------------------------------------*/
    handle = mmi_phb_cntx_mgr_create_handle(MMI_PHB_SG_MARK_SEVERAL);
    new_sg_id = mmi_phb_cntx_mgr_get_sg_id(handle);
    mmi_phb_cntx_mgr_set_parent_id(handle, sg_id);
    list_cntx = cui_phb_list_select_contact_create_cntx(MMI_PHB_LIST_TYPE_MULTI_SELECT);
    
    list_cntx->sg_id = new_sg_id;
    list_cntx->parent_id = sg_id;

    if (sg_id == GRP_ID_PHB_MAIN)
    {
        parent_data = (mmi_phb_list_cntx_struct *) mmi_frm_group_get_user_data(sg_id);
        list_cntx->list_index = parent_data->list_index;
    }
    
    mmi_phb_cntx_mgr_set_data(handle, list_cntx);

    cui_phb_list_select_contact_set_cntx(list_cntx);

    mmi_frm_group_create(
        sg_id,
        new_sg_id,
        cui_phb_list_select_contact_proc,
        list_cntx);
    mmi_frm_group_enter(new_sg_id, MMI_FRM_NODE_SMART_CLOSE_FLAG);
    
    g_mmi_phb_mark_several_entry_func();
}


/*****************************************************************************
 * FUNCTION
 *  mmi_phb_highlight_mark_several_main
 * DESCRIPTION
 *  Highlight handler for "mark several" in PHB main menu
 * PARAMETERS
 *  void
 * RETURNS
 *  void
 *****************************************************************************/
void mmi_phb_highlight_mark_several_main(void)
{  
    /*----------------------------------------------------------------*/
    /* Local Variables                                                */
    /*----------------------------------------------------------------*/

    /*----------------------------------------------------------------*/
    /* Code Body                                                      */
    /*----------------------------------------------------------------*/
    g_mmi_phb_mark_several_entry_func = mmi_phb_entry_mark_several_main;
    
    //ChangeLeftSoftkey(STR_GLOBAL_OK, IMG_GLOBAL_OK);
    //ChangeRightSoftkey(STR_GLOBAL_BACK, IMG_GLOBAL_BACK);

    //SetLeftSoftkeyFunction(mmi_phb_pre_entry_mark_several_main, KEY_EVENT_UP);
    //SetRightSoftkeyFunction(mmi_frm_scrn_close_active_id, KEY_EVENT_UP);
}

#endif /* defined(__MMI_PHB_MULTI_OPERATION__) */


#define MMI_PHB_LIST_MULTI_SELECT

#if defined(__MMI_PHB_GENERIC_MULTI_SELECT__)

#ifdef __MMI_FTE_SUPPORT__
/*****************************************************************************
 * FUNCTION
 *  mmi_phb_fte_contact_list_tap_callback
 * DESCRIPTION
 *  fte contact main list tap callback
 * PARAMETERS
 *  void
 * RETURNS
 *  void
 *****************************************************************************/
static void mmi_phb_fte_mark_generic_list_tap_callback(mmi_tap_type_enum tap_type, S32 index)
{
    /*----------------------------------------------------------------*/
    /* Local Variables                                                */
    /*----------------------------------------------------------------*/

    /*----------------------------------------------------------------*/
    /* Code Body                                                      */
    /*----------------------------------------------------------------*/
    mmi_phb_mark_several_check();
}
#endif /* __MMI_FTE_SUPPORT__ */



/*****************************************************************************
 * FUNCTION
 *  mmi_phb_mark_several_for_msg_get_number
 * DESCRIPTION
 *  Get entry function of mark several list used for message (SMS, MMS...)
 * PARAMETERS
 *  dest            [IN]        Dest buffer
 *  max_dest_len    [IN]        Size of dest buffer in bytes
 *  PhbIndex        [IN]        Phb store index
 *  num_type        [IN]        Number type
 * RETURNS
 *  void
 *****************************************************************************/
void mmi_phb_mark_several_for_msg_get_number(U8 *dest, U8 max_dest_len, U16 PhbIndex, U8 num_type)
{
    /*----------------------------------------------------------------*/
    /* Local Variables                                                */
    /*----------------------------------------------------------------*/

    /*----------------------------------------------------------------*/
    /* Code Body                                                      */
    /*----------------------------------------------------------------*/
    switch (num_type)
    {
        case MMI_PHB_NUMBER_TYPE_NUMBER:
        {
            U16 number[MMI_PHB_NUMBER_LENGTH + 1 + 1];
            srv_phb_get_number(PhbIndex, number, MMI_PHB_NUMBER_LENGTH + 1);
            mmi_phb_truncate_number_field_to_max_len((U16 *) dest, number, max_dest_len);
            break;
        }
        
    #if !defined(__MMI_PHB_NO_OPTIONAL_FIELD__)    
        case MMI_PHB_NUMBER_TYPE_EMAIL_ADDRESS:
        {
            U16 email[MMI_PHB_EMAIL_LENGTH + 1];
            srv_phb_get_email_address(PhbIndex, email, MMI_PHB_EMAIL_LENGTH);
            mmi_ucs2ncpy((S8 *) dest, (S8 *) email, max_dest_len);
            break;
        }
    #endif
    
    #if !defined(__MMI_PHB_NO_OPTIONAL_FIELD__)
    #if defined(__MMI_PHB_OPTIONAL_FIELDS_2ND_EMAIL__)
        case MMI_PHB_NUMBER_TYPE_EMAIL_ADDRESS_2:
        {
            U16 email[MMI_PHB_EMAIL_LENGTH + 1];
            srv_phb_get_email_address2(PhbIndex, email, MMI_PHB_EMAIL_LENGTH);
            mmi_ucs2ncpy((S8 *) dest, (S8 *) email, max_dest_len);
            break;
        }
    #endif
    #endif /* !defined(__MMI_PHB_NO_OPTIONAL_FIELD__) */

        default:
            break;
    }
}


void mmi_phb_generic_mark_several_select_number_back(void)
{
    /*----------------------------------------------------------------*/
    /* Local Variables                                                */
    /*----------------------------------------------------------------*/

    /*----------------------------------------------------------------*/
    /* Code Body                                                      */
    /*----------------------------------------------------------------*/
    mmi_frm_scrn_close_active_id();
}

void mmi_phb_generic_mark_several_select_number_more(void)
{
    /*----------------------------------------------------------------*/
    /* Local Variables                                                */
    /*----------------------------------------------------------------*/
    mmi_id sg_id = mmi_phb_cntx_mgr_get_current_sg_id();

    /*----------------------------------------------------------------*/
    /* Code Body                                                      */
    /*----------------------------------------------------------------*/
    /* since it is a timeout function, so check if the sg exist */
    if (sg_id == GRP_ID_INVALID)
    {
        return;
    }
    
    switch (g_mmi_phb_choose_field.number_type[g_mmi_phb_choose_field.highlight_index])
    {
        case SRV_PHB_ENTRY_FIELD_NUMBER:
            g_mmi_phb_list_p->mark_field[g_mmi_phb_list_p->list_index] = MMI_PHB_NUMBER_TYPE_NUMBER;
            break;
            
        case SRV_PHB_ENTRY_FIELD_OPT_NUM_1:
            g_mmi_phb_list_p->mark_field[g_mmi_phb_list_p->list_index] = MMI_PHB_NUMBER_TYPE_HOME_NUMBER;
            break;
            
        case SRV_PHB_ENTRY_FIELD_OPT_NUM_2:
            g_mmi_phb_list_p->mark_field[g_mmi_phb_list_p->list_index] = MMI_PHB_NUMBER_TYPE_OFFICE_NUMBER;
            break;
            
        case SRV_PHB_ENTRY_FIELD_OPT_NUM_3:
            g_mmi_phb_list_p->mark_field[g_mmi_phb_list_p->list_index] = MMI_PHB_NUMBER_TYPE_FAX_NUMBER;
            break;
            
        case SRV_PHB_ENTRY_FIELD_EMAIL1:
            g_mmi_phb_list_p->mark_field[g_mmi_phb_list_p->list_index] = MMI_PHB_NUMBER_TYPE_EMAIL_ADDRESS;
            break;
            
        case SRV_PHB_ENTRY_FIELD_EMAIL2:
            g_mmi_phb_list_p->mark_field[g_mmi_phb_list_p->list_index] = MMI_PHB_NUMBER_TYPE_EMAIL_ADDRESS_2;
            break;
            
        default:
            break;
    }

    g_mmi_phb_list_p->list_index++;
    
    mmi_frm_display_dummy_screen();
    mmi_frm_scrn_close(mmi_phb_cntx_mgr_get_current_sg_id(), SCR_CHOOSE_NUMBER);

    if (g_mmi_phb_list_p->list_index < g_mmi_phb_list_p->mark_count)
    {
        mmi_phb_generic_mark_several_select_number_pre_entry();
    }
    else
    {
        g_mmi_phb_list_p->evt_out = MMI_TRUE;
        cui_phb_list_multi_select_contact_emit(
            g_mmi_phb_list_p->sg_id,
            EVT_ID_PHB_SELECT_MULTI_CONTACT,
            g_mmi_phb_list_p->mark_count,
            g_mmi_phb_list_p->mark_array,
            g_mmi_phb_list_p->mark_field,
            MMI_FALSE);
    }
}


/*****************************************************************************
 * FUNCTION
 *  mmi_phb_generic_mark_several_select_number_pre_entry
 * DESCRIPTION
 *  
 * PARAMETERS
 *  void
 * RETURNS
 *  void
 *****************************************************************************/
void mmi_phb_generic_mark_several_select_number_pre_entry(void)
{
    /*----------------------------------------------------------------*/
    /* Local Variables                                                */
    /*----------------------------------------------------------------*/

    /*----------------------------------------------------------------*/
    /* Code Body                                                      */
    /*----------------------------------------------------------------*/
    mmi_phb_entry_choose_field(
        g_mmi_phb_list_p->sg_id,
        g_mmi_phb_list_p->mark_array[g_mmi_phb_list_p->list_index],
        g_mmi_phb_list_p->filter,
        mmi_phb_generic_mark_several_select_number_pre_entry,
        mmi_phb_generic_mark_several_select_number_more,
        mmi_phb_generic_mark_several_select_number_back,
        NULL,
        MMI_FALSE,
        MMI_TRUE);
}


#if defined(__MMI_MESSAGES_SEND_BY_GROUP__) || defined(__MMI_UNIFIED_COMPOSER__) || defined(__MMI_MMS_STANDALONE_COMPOSER__) || defined(__MMI_JATAAYU_MMS_ADD_NUMBER_BY_GROUP__)
/*****************************************************************************
 * FUNCTION
 *  mmi_phb_generic_mark_several_list_done_for_group
 * DESCRIPTION
 *  Sends the names & numbers info of the selected
 *  caller group to SMS
 * PARAMETERS
 *  void
 * RETURNS
 *  void
 *****************************************************************************/
void mmi_phb_generic_mark_several_list_done_for_group(void)
{
    /*----------------------------------------------------------------*/
    /* Local Variables                                                */
    /*----------------------------------------------------------------*/
    srv_phb_filter_struct *filter;
    srv_phb_group_filter_struct group_filter;

    /*----------------------------------------------------------------*/
    /* Code Body                                                      */
    /*----------------------------------------------------------------*/
    /* Clear key immediately to avoid user press twice. */
    ClearKeyHandler(KEY_LSK, KEY_EVENT_UP);

    group_filter.group_mask = (U32)(1 << g_mmi_phb_list_p->group_id);
    group_filter.is_equal = MMI_TRUE;
    
    filter = mmi_phb_list_build_filter(
                g_mmi_phb_list_p->storage,
                g_mmi_phb_list_p->filter,
                &group_filter,
                NULL,
                0);

    g_mmi_phb_list_p->mark_count = (U16) srv_phb_oplib_build_contact_list(filter, g_mmi_phb_list_p->mark_array, MMI_PHB_ENTRIES);

    mmi_phb_list_free_filter(filter);
}


void mmi_frm_scrn_close_active_id_ext(MMI_ID group_id)
{
    mmi_frm_scrn_close_active_id();
}


/*****************************************************************************
 * FUNCTION
 *  mmi_phb_generic_mark_several_list_add_confirm
 * DESCRIPTION
 *  
 * PARAMETERS
 *  void
 * RETURNS
 *  void
 *****************************************************************************/
void mmi_phb_generic_mark_several_list_add_confirm(void)
{
    /*----------------------------------------------------------------*/
    /* Local Variables                                                */
    /*----------------------------------------------------------------*/

    /*----------------------------------------------------------------*/
    /* Code Body                                                      */
    /*----------------------------------------------------------------*/
    mmi_phb_generic_mark_several_list_done_for_group();
    
    if (g_mmi_phb_list_p->mark_count == 0)
    {
        mmi_popup_display_simple(
            (UI_string_type)GetString(STR_ID_PHB_NO_ENTRY_TO_SELECT),
            MMI_EVENT_FAILURE,
            g_mmi_phb_list_p->sg_id,
            NULL);

        return;
    }
    
    if (g_mmi_phb_list_p->mark_count <= g_mmi_phb_list_p->select_count)
    {
        mmi_phb_mark_several_select_field(GRP_ID_PHB_MARK_SEVERAL);
        return;
    }

    g_mmi_phb_list_p->mark_count = g_mmi_phb_list_p->select_count;
    
    mmi_phb_continue_send_multi_message_confirm(
        g_mmi_phb_list_p->select_count,
        mmi_phb_mark_several_select_field,
        mmi_frm_scrn_close_active_id_ext,
        g_mmi_phb_list_p->sg_id);
}
#endif /* defined(__MMI_MESSAGES_SEND_BY_GROUP__) || defined(__MMI_UNIFIED_COMPOSER__) || defined(__MMI_MMS_STANDALONE_COMPOSER__) || defined(__MMI_JATAAYU_MMS_ADD_NUMBER_BY_GROUP__) */ 


/*****************************************************************************
 * FUNCTION
 *  mmi_phb_mark_several_list_highlight_handler
 * DESCRIPTION
 *  
 * PARAMETERS
 *  void
 * RETURNS
 *  void
 *****************************************************************************/
void mmi_phb_mark_several_list_highlight_handler(S32 item_index)
{
    /*----------------------------------------------------------------*/
    /* Local Variables                                                */
    /*----------------------------------------------------------------*/
    
    /*----------------------------------------------------------------*/
    /* Code Body                                                      */
    /*----------------------------------------------------------------*/   
    MMI_ASSERT(item_index < g_mmi_phb_list_p->contact_count);

    g_mmi_phb_list_p->list_index = (U16) item_index;
    g_mmi_phb_list_p->store_index = g_mmi_phb_list_p->contact_array[item_index];
    
    ChangeCenterSoftkey(0, IMG_ID_PHB_CSK_MARK);

#if defined(__MMI_INTELLIGENT_CALL_ALERT__)
    mmi_phb_speak_name_start();
#endif
}


static void mmi_phb_mark_several_list_highlight_handler_tab(S32 item_index)
{
    /*----------------------------------------------------------------*/
    /* Local Variables                                                */
    /*----------------------------------------------------------------*/
    
    /*----------------------------------------------------------------*/
    /* Code Body                                                      */
    /*----------------------------------------------------------------*/   
    mmi_phb_mark_several_list_highlight_handler(item_index);

    SetKeyHandler(mmi_frm_general_tab_l_arrow_key_hdlr, KEY_LEFT_ARROW, KEY_EVENT_DOWN);
    SetKeyHandler(mmi_frm_general_tab_r_arrow_key_hdlr, KEY_RIGHT_ARROW, KEY_EVENT_DOWN); 
}


/*****************************************************************************
 * FUNCTION
 *  mmi_phb_mark_several_list_done
 * DESCRIPTION
 *  set check box
 * PARAMETERS
 *  void
 * RETURNS
 *  void
 *****************************************************************************/
static void mmi_phb_mark_several_list_done(void)
{
    /*----------------------------------------------------------------*/
    /* Local Variables                                                */
    /*----------------------------------------------------------------*/
    U16 mark_count;

    /*----------------------------------------------------------------*/
    /* Code Body                                                      */
    /*----------------------------------------------------------------*/
    mark_count = mmi_phb_mark_several_populate();

    /* if not select any one, then use the highlight one */
    if (mark_count == 0)
    {
        mark_count = 1;
        g_mmi_phb_list_p->mark_array[0] = g_mmi_phb_list_p->contact_array[g_mmi_phb_list_p->list_index];
    }

    g_mmi_phb_list_p->evt_out = MMI_TRUE;
    cui_phb_list_multi_select_contact_emit(
        g_mmi_phb_list_p->sg_id,
        EVT_ID_PHB_SELECT_MULTI_CONTACT,
        mark_count,
        g_mmi_phb_list_p->mark_array,
        NULL,
        MMI_FALSE);
}


/*****************************************************************************
 * FUNCTION
 *  mmi_phb_mark_several_go_back_history
 * DESCRIPTION
 *  go back history
 * PARAMETERS
 *  void
 * RETURNS
 *  void
 *****************************************************************************/
static void mmi_phb_generic_mark_several_go_back_history(void)
{
    /*----------------------------------------------------------------*/
    /* Local Variables                                                */
    /*----------------------------------------------------------------*/

    /*----------------------------------------------------------------*/
    /* Code Body                                                      */
    /*----------------------------------------------------------------*/
    mmi_frm_scrn_close_active_id();
}


/*****************************************************************************
 * FUNCTION
 *  mmi_phb_exit_generic_mark_several
 * DESCRIPTION
 *  Exit function
 * PARAMETERS
 *  void
 * RETURNS
 *  void
 *****************************************************************************/
void mmi_phb_exit_generic_mark_several(void)
{
    /*----------------------------------------------------------------*/
    /* Local Variables                                                */
    /*----------------------------------------------------------------*/

    /*----------------------------------------------------------------*/
    /* Code Body                                                      */
    /*----------------------------------------------------------------*/
#if defined(__MMI_PHB_QUICK_SEARCH__)
	mmi_imc_key_set_pre_key_handler(NULL);
#endif

#if defined(__MMI_INTELLIGENT_CALL_ALERT__)
    mmi_phb_speak_name_end();
#endif
}


/*****************************************************************************
 * FUNCTION
 *  mmi_phb_entry_generic_multi_select_list
 * DESCRIPTION
 *  entry function
 * PARAMETERS
 *  void
 * RETURNS
 *  void
 *****************************************************************************/
void mmi_phb_entry_generic_mark_several(void)
{
    /*----------------------------------------------------------------*/
    /* Local Variables                                                */
    /*----------------------------------------------------------------*/
    U8 *gui_buffer;
    U16 entry_count;
    srv_phb_filter_struct *filter;
    U32 handle;
    mmi_phb_refresh_struct *refresh_data;

    /*----------------------------------------------------------------*/
    /* Code Body                                                      */
    /*----------------------------------------------------------------*/
    if (!mmi_phb_check_ready(MMI_TRUE))
    {
        return;
    }

    filter = mmi_phb_list_build_filter(
                 g_mmi_phb_list_p->storage,
                 g_mmi_phb_list_p->filter, 
                 &g_mmi_phb_list_p->group_filter,
                 NULL,
                 0);
    entry_count = (U16) srv_phb_oplib_build_contact_list(filter, g_mmi_phb_list_p->contact_array, MMI_PHB_ENTRIES);
    g_mmi_phb_list_p->contact_count = entry_count;

    mmi_phb_list_free_filter(filter);
    
    if (entry_count == 0)
    {
        mmi_popup_display_simple(
            (UI_string_type)GetString(STR_ID_PHB_NO_ENTRY_TO_SELECT),
            MMI_EVENT_FAILURE,
            g_mmi_phb_list_p->sg_id,
            NULL);

        return;
    }
    if (mmi_frm_scrn_enter(
            g_mmi_phb_list_p->sg_id,
            SCR_ID_PHB_GENERIC_MULTI_SELECT,
            mmi_phb_exit_generic_mark_several,
            mmi_phb_entry_generic_mark_several,
            MMI_FRM_FULL_SCRN))
    {            
        gui_buffer = mmi_frm_scrn_get_active_gui_buf();

        RegisterHighlightHandler(mmi_phb_mark_several_list_highlight_handler);

        if (gui_buffer == NULL)
        {
            g_mmi_phb_list_p->list_index = 0;
        }
        else        
        {
            if (!mmi_is_redrawing_bk_screens())
            {
                handle = mmi_phb_cntx_mgr_get_handle_by_sg_id(mmi_phb_cntx_mgr_get_current_sg_id());
                refresh_data = mmi_phb_cntx_mgr_get_refresh_data(handle);
                
                if (refresh_data != NULL && refresh_data->refresh_type != MMI_PHB_OP_NONE)
                {
                    gui_buffer = NULL;
                    g_mmi_phb_list_p->list_index = 0;
                    
                #if defined(__MMI_PHB_QUICK_SEARCH__)
                    g_mmi_phb_list_p->qsearch_input_buffer[0] = 0;
                #endif
                    memset(g_mmi_phb_list_p->bitmask, 0, (MMI_PHB_ENTRIES + 7) / 8);

                    refresh_data->refresh_type = MMI_PHB_OP_NONE;
                }
            }
        }
        
    #ifdef __MMI_UI_HINTS_IN_MENUITEM__
        set_force_icon_on_highlight_only_in_menuitem();
    #endif

        EnableCenterSoftkey(0, IMG_ID_PHB_CSK_MARK);
    
    #if defined(__MMI_PHB_QUICK_SEARCH__)
    
        RegisterCat200SearchFunction(mmi_phb_quick_search_find_entry);
        g_phb_quick_search_enter = MMI_PHB_QUICK_SEARCH_GENERIC;
        
        if (gui_buffer != NULL)
        {
            entry_count = (U16) mmi_phb_quick_search_find_entry((U8 *) g_mmi_phb_list_p->qsearch_input_buffer);
        }
        
        ShowCategory202Screen(
            STR_SCR_PBOOK_VIEW_CAPTION,
            IMG_SCR_PBOOK_CAPTION,
            STR_GLOBAL_ADD,
            IMG_GLOBAL_OK,
            STR_GLOBAL_BACK,
            IMG_GLOBAL_BACK,
            NULL,
            entry_count,
            mmi_phb_list_get_item,
            mmi_phb_list_get_hint,
            mmi_phb_mark_several_get_state,
            mmi_phb_mark_several_set_state,
            g_mmi_phb_list_p->list_index,
            IMG_ID_PHB_QUICK_SEARCH_FIND,
            (U8*) g_mmi_phb_list_p->qsearch_input_buffer,
            MMI_PHB_QUICK_SEARCH_INPUT_LENGTH,
            gui_buffer);
        
        SetLeftSoftkeyFunction(mmi_phb_mark_several_list_done, KEY_EVENT_UP);
        SetCategory200LeftSoftkeyFunction(mmi_phb_mark_several_list_done, KEY_EVENT_UP);
        SetCategory200RightSoftkeyFunction(mmi_phb_generic_mark_several_go_back_history, KEY_EVENT_UP);
    #else
        ShowCategory384Screen(
            (UI_string_type)GetString(STR_SCR_PBOOK_VIEW_CAPTION),
            (PU8)GetImage(IMG_SCR_PBOOK_CAPTION),
            STR_GLOBAL_ADD,
            IMG_GLOBAL_OK,
            STR_GLOBAL_BACK,
            IMG_GLOBAL_BACK,
            NULL,
            entry_count,
            mmi_phb_list_get_item,
            mmi_phb_list_get_hint,
            mmi_phb_mark_several_get_state,
            mmi_phb_mark_several_set_state,
            0,
            gui_buffer);
    
    
        SetLeftSoftkeyFunction(mmi_phb_mark_several_list_done, KEY_EVENT_UP);
        SetRightSoftkeyFunction(mmi_phb_generic_mark_several_go_back_history, KEY_EVENT_UP);
    #endif
    
    #ifdef __MMI_TOUCH_SCREEN__
        wgui_register_list_item_selected_callback_all(UI_dummy_function);
    #endif

        SetCenterSoftkeyFunction(mmi_phb_mark_several_check, KEY_EVENT_UP);
    
        mmi_imc_key_set_pre_key_handler(mmi_phb_star_key_pre_handler);

    #ifdef __MMI_FTE_SUPPORT__
        wgui_register_tap_callback(mmi_phb_fte_mark_generic_list_tap_callback);
    #endif
    }
}

void mmi_phb_mark_several_select_field(MMI_ID group_id)
{
    /*----------------------------------------------------------------*/
    /* Local Variables                                                */
    /*----------------------------------------------------------------*/
    U16 i;

    /*----------------------------------------------------------------*/
    /* Code Body                                                      */
    /*----------------------------------------------------------------*/
    switch (g_mmi_phb_list_p->filter)
    {
        case SRV_PHB_ENTRY_FIELD_NUMBER:
            for (i = 0; i < g_mmi_phb_list_p->mark_count; i++)
            {
                g_mmi_phb_list_p->mark_field[i] = MMI_PHB_NUMBER_TYPE_NUMBER;
            }

            g_mmi_phb_list_p->evt_out = MMI_TRUE;
            cui_phb_list_multi_select_contact_emit(
                g_mmi_phb_list_p->sg_id,
                EVT_ID_PHB_SELECT_MULTI_CONTACT,
                g_mmi_phb_list_p->mark_count,
                g_mmi_phb_list_p->mark_array,
                g_mmi_phb_list_p->mark_field,
                MMI_FALSE);
            break;
            
    #if !defined(__MMI_PHB_OPTIONAL_FIELDS_2ND_EMAIL__)
        case SRV_PHB_ENTRY_FIELD_EMAIL:
    #endif
            for (i = 0; i < g_mmi_phb_list_p->mark_count; i++)
            {
                g_mmi_phb_list_p->mark_field[i] = MMI_PHB_NUMBER_TYPE_EMAIL_ADDRESS;
            }

            g_mmi_phb_list_p->evt_out = MMI_TRUE;           
            cui_phb_list_multi_select_contact_emit(
                g_mmi_phb_list_p->sg_id,
                EVT_ID_PHB_SELECT_MULTI_CONTACT,
                g_mmi_phb_list_p->mark_count,
                g_mmi_phb_list_p->mark_array,
                g_mmi_phb_list_p->mark_field,
                MMI_FALSE);
            break;
            
    #if defined(__MMI_PHB_OPTIONAL_FIELDS_2ND_EMAIL__)
        case SRV_PHB_ENTRY_FIELD_EMAIL:
    #endif
        case SRV_PHB_ENTRY_FIELD_NUMBER | SRV_PHB_ENTRY_FIELD_EMAIL:
            /**
             * use list highlight index to build field array
             */
            g_mmi_phb_list_p->list_index = 0;
            mmi_phb_generic_mark_several_select_number_pre_entry();
            break;
            
        default:
            break;
    }

}

/*****************************************************************************
 * FUNCTION
 *  mmi_phb_mark_several_tab_done
 * DESCRIPTION
 *  set check box
 * PARAMETERS
 *  void
 * RETURNS
 *  void
 *****************************************************************************/
static void mmi_phb_mark_several_tab_done(void)
{
    /*----------------------------------------------------------------*/
    /* Local Variables                                                */
    /*----------------------------------------------------------------*/

    /*----------------------------------------------------------------*/
    /* Code Body                                                      */
    /*----------------------------------------------------------------*/
    g_mmi_phb_list_p->mark_count = mmi_phb_mark_several_populate();

    /* if not select any one, then use the highlight one */
    if (g_mmi_phb_list_p->mark_count == 0)
    {
        g_mmi_phb_list_p->mark_count = 1;
        g_mmi_phb_list_p->mark_array[0] = g_mmi_phb_list_p->contact_array[g_mmi_phb_list_p->list_index];
    }

    mmi_phb_mark_several_select_field(GRP_ID_PHB_MARK_SEVERAL);
}


static pBOOL mmi_phb_mark_several_group_get_item(S32 item_index, UI_string_type str_buff, PU8 *img_buff_p, U8 str_img_mask)
{
    /*----------------------------------------------------------------*/
    /* Local Variables                                                */
    /*----------------------------------------------------------------*/

    /*----------------------------------------------------------------*/
    /* Code Body                                                      */
    /*----------------------------------------------------------------*/    
    srv_phb_get_group_name(g_mmi_phb_list_p->group_array[item_index], (U16*)str_buff, MAX_SUBMENU_CHARACTERS);

    *img_buff_p = get_image(gIndexIconsImageList[item_index]);

    return TRUE;
}


/*****************************************************************************
 * FUNCTION
 *  mmi_phb_mark_several_group_highlight_hdlr
 * DESCRIPTION
 *  
 * PARAMETERS
 *  index       [IN]        
 * RETURNS
 *  void
 *****************************************************************************/
void mmi_phb_mark_several_group_highlight_hdlr(S32 index)
{
    /*----------------------------------------------------------------*/
    /* Local Variables                                                */
    /*----------------------------------------------------------------*/

    /*----------------------------------------------------------------*/
    /* Code Body                                                      */
    /*----------------------------------------------------------------*/    
    g_mmi_phb_list_p->group_id = g_mmi_phb_list_p->group_array[index];

    SetKeyHandler(mmi_frm_general_tab_l_arrow_key_hdlr, KEY_LEFT_ARROW, KEY_EVENT_DOWN);
    SetKeyHandler(mmi_frm_general_tab_r_arrow_key_hdlr, KEY_RIGHT_ARROW, KEY_EVENT_DOWN); 
}


static void mmi_phb_exit_generic_mark_several_tab0(void)
{
    /*----------------------------------------------------------------*/
    /* Local Variables                                                */
    /*----------------------------------------------------------------*/

    /*----------------------------------------------------------------*/
    /* Code Body                                                      */
    /*----------------------------------------------------------------*/

#if defined(__MMI_INTELLIGENT_CALL_ALERT__)
    mmi_phb_speak_name_end();
#endif
}


/*****************************************************************************
 * FUNCTION
 *  mmi_phb_entry_generic_mark_several_tab0
 * DESCRIPTION
 *  
 * PARAMETERS
 *  void
 * RETURNS
 *  void
 *****************************************************************************/
void mmi_phb_entry_generic_mark_several_tab0(void)
{
    /*----------------------------------------------------------------*/
    /* Local Variables                                                */
    /*----------------------------------------------------------------*/
    U8 *gui_buffer;
    U16 entry_count;
    U32 handle;
    mmi_phb_refresh_struct *refresh_data;

    /*----------------------------------------------------------------*/
    /* Code Body                                                      */
    /*----------------------------------------------------------------*/
    if (mmi_frm_scrn_enter(
            g_mmi_phb_list_p->sg_id,
            SCR_ID_PHB_MARK_SEVERAL_TAB_0,
            mmi_phb_exit_generic_mark_several_tab0,
            mmi_phb_entry_generic_mark_several_tab0,
            MMI_FRM_TAB_PAGE))
    {        
        gui_buffer = mmi_frm_scrn_get_active_gui_buf();
        RegisterHighlightHandler(mmi_phb_mark_several_list_highlight_handler_tab);

        if (gui_buffer == NULL)
        {
            g_mmi_phb_list_p->list_index = 0;
            entry_count = g_mmi_phb_list_p->contact_count;
        }
        else        
        {
            if (!mmi_is_redrawing_bk_screens())
            {
                handle = mmi_phb_cntx_mgr_get_handle_by_sg_id(mmi_phb_cntx_mgr_get_current_sg_id());
                refresh_data = mmi_phb_cntx_mgr_get_refresh_data(handle);
                
                if (refresh_data != NULL && refresh_data->refresh_type != MMI_PHB_OP_NONE)
                {
                    gui_buffer = NULL;
                    g_mmi_phb_list_p->list_index = 0;
                    
                #if defined(__MMI_PHB_QUICK_SEARCH__)
                    g_mmi_phb_list_p->qsearch_input_buffer[0] = 0;
                #endif
                    memset(g_mmi_phb_list_p->bitmask, 0, (MMI_PHB_ENTRIES + 7) / 8);

                    refresh_data->refresh_type = MMI_PHB_OP_NONE;
                }
            }
        }

        EnableCenterSoftkey(0, IMG_ID_PHB_CSK_MARK);

    #if defined(__MMI_PHB_QUICK_SEARCH__)
        RegisterCat200SearchFunction(mmi_phb_quick_search_find_entry_tab);
        g_phb_quick_search_enter = MMI_PHB_QUICK_SEARCH_GENERIC;

        if (gui_buffer != NULL)
        {
            entry_count = (U16) mmi_phb_quick_search_find_entry_tab((U8 *) g_mmi_phb_list_p->qsearch_input_buffer);
        }
        
        ShowCategory199Screen(
            (UI_string_type) GetString(STR_GLOBAL_ADD),
            NULL,
            (UI_string_type) GetString(STR_GLOBAL_BACK),
            NULL,
            0,
            (UI_string_type) GetString(STR_SCR_PBOOK_VIEW_CAPTION),
            (UI_string_type) NULL,
            entry_count,
            mmi_phb_list_get_item,
            mmi_phb_list_get_hint,
            mmi_phb_mark_several_get_state,
            mmi_phb_mark_several_set_state,
            g_mmi_phb_list_p->list_index,
            (U8*) g_mmi_phb_list_p->qsearch_input_buffer,
            MMI_PHB_QUICK_SEARCH_INPUT_LENGTH,
            gui_buffer);
        
        SetLeftSoftkeyFunction(mmi_phb_mark_several_tab_done, KEY_EVENT_UP);
        SetCategory200LeftSoftkeyFunction(mmi_phb_mark_several_tab_done, KEY_EVENT_UP);
        SetCategory200RightSoftkeyFunction(mmi_phb_generic_mark_several_go_back_history, KEY_EVENT_UP);
    #else
        ShowCategory628Screen(
            (UI_string_type) GetString(STR_SCR_PBOOK_VIEW_CAPTION),
            (PU8) GetImage(IMG_SCR_PBOOK_CAPTION),
            STR_GLOBAL_ADD,
            0,
            STR_GLOBAL_BACK,
            0,
            NULL,
            g_mmi_phb_list_p->contact_count,
            mmi_phb_list_get_item,
            mmi_phb_list_get_hint,
            mmi_phb_mark_several_get_state,
            mmi_phb_mark_several_set_state,
            g_mmi_phb_list_p->list_index,
            0,
            gui_buffer);
    
        SetLeftSoftkeyFunction(mmi_phb_mark_several_tab_done, KEY_EVENT_UP);
        SetRightSoftkeyFunction(mmi_phb_generic_mark_several_go_back_history, KEY_EVENT_UP);
    #endif

    #ifdef __MMI_TOUCH_SCREEN__
        wgui_register_list_item_selected_callback_all(UI_dummy_function);
    #endif

    #ifdef __MMI_TOUCH_SCREEN__
        wgui_set_horizontal_tab_bar_select_callback(mmi_frm_set_cur_sel_page);
    #endif /* __MMI_TOUCH_SCREEN__ */

        SetCenterSoftkeyFunction(mmi_phb_mark_several_check, KEY_EVENT_UP);

        mmi_imc_key_set_pre_key_handler(mmi_phb_star_key_pre_handler);

    #ifdef __MMI_FTE_SUPPORT__
        wgui_register_tap_callback(mmi_phb_fte_mark_generic_list_tap_callback);
    #endif
    }
}


/*****************************************************************************
 * FUNCTION
 *  mmi_phb_entry_generic_mark_several_set_viewer_key
 * DESCRIPTION
 *  Set viewer key handler
 * PARAMETERS
 *  void
 * RETURNS
 *  void
 *****************************************************************************/
static void mmi_phb_entry_generic_mark_several_set_viewer_key(void)
{
    /*----------------------------------------------------------------*/
    /* Local Variables                                                */
    /*----------------------------------------------------------------*/
    
    /*----------------------------------------------------------------*/
    /* Code Body                                                      */
    /*----------------------------------------------------------------*/
    /* register arrow key, because FW2.0 restrict */
    SetKeyHandler(mmi_frm_general_tab_l_arrow_key_hdlr, KEY_LEFT_ARROW, KEY_EVENT_DOWN);
    SetKeyHandler(mmi_frm_general_tab_r_arrow_key_hdlr, KEY_RIGHT_ARROW, KEY_EVENT_DOWN); 
}


/*****************************************************************************
 * FUNCTION
 *  mmi_phb_entry_generic_mark_several_tab1
 * DESCRIPTION
 *  
 * PARAMETERS
 *  void
 * RETURNS
 *  void
 *****************************************************************************/
void mmi_phb_entry_generic_mark_several_tab1(void)
{
    /*----------------------------------------------------------------*/
    /* Local Variables                                                */
    /*----------------------------------------------------------------*/
    U8 *gui_buffer;
    U8 group_count = 0;
    U16 str_id = STR_ID_PHB_NO_GROUP;
    
    /*----------------------------------------------------------------*/
    /* Code Body                                                      */
    /*----------------------------------------------------------------*/
    if (!mmi_frm_scrn_enter(
            g_mmi_phb_list_p->sg_id,
            SCR_ID_PHB_MARK_SEVERAL_TAB_1,
            NULL,
            mmi_phb_entry_generic_mark_several_tab1,
            MMI_FRM_TAB_PAGE))
    {
        return;
    }

    gui_buffer = mmi_frm_scrn_get_active_gui_buf();
    RegisterHighlightHandler(mmi_phb_mark_several_group_highlight_hdlr);

    if (g_mmi_phb_list_p->storage == PHB_STORAGE_SIM || g_mmi_phb_list_p->storage == PHB_STORAGE_SIM2)
    {
        str_id = STR_ID_PHB_NO_GROUP_INFO;
    }
    else
    {
        group_count = srv_phb_datamgr_get_group_list(g_mmi_phb_list_p->group_array, NULL);
    }

    if (group_count > 0)
    {
        EnableCenterSoftkey(0, IMG_GLOBAL_COMMON_CSK);
	
        ShowCategory629Screen(
            STR_SCR_CALLER_GROUP_CAPTION,
            IMG_SCR_PBOOK_CAPTION,
            STR_GLOBAL_ADD,
            0,
            STR_GLOBAL_BACK,
            0,
            group_count,
            mmi_phb_mark_several_group_get_item,
            NULL,
            0,
            1,
            gui_buffer);
        
    #if defined(__MMI_MESSAGES_SEND_BY_GROUP__) || defined(__MMI_UNIFIED_COMPOSER__) || defined(__MMI_MMS_STANDALONE_COMPOSER__) || defined(__MMI_JATAAYU_MMS_ADD_NUMBER_BY_GROUP__)
        SetLeftSoftkeyFunction(mmi_phb_generic_mark_several_list_add_confirm, KEY_EVENT_UP);
        SetCenterSoftkeyFunction(mmi_phb_generic_mark_several_list_add_confirm, KEY_EVENT_UP);
    #endif
    }
    else
    {
        wgui_cat3001_show(
            get_string(STR_SCR_CALLER_GROUP_CAPTION),
            0,
            0,
            get_string(STR_GLOBAL_BACK),
            get_image(IMG_GLOBAL_BACK),
            (S8)1,
            MMI_TRUE,
            (U8*) GetString(str_id),
            100,
            gui_buffer);

        //wgui_inputs_ml_register_set_key_callback(mmi_phb_entry_generic_mark_several_set_viewer_key);
    }
    
#ifdef __MMI_TOUCH_SCREEN__
    wgui_set_horizontal_tab_bar_select_callback(mmi_frm_set_cur_sel_page);
#endif /* __MMI_TOUCH_SCREEN__ */

    SetRightSoftkeyFunction(mmi_phb_generic_mark_several_go_back_history, KEY_EVENT_UP);

    /* register arrow key, because FW2.0 restrict */
    SetKeyHandler(mmi_frm_general_tab_l_arrow_key_hdlr, KEY_LEFT_ARROW, KEY_EVENT_DOWN);
    SetKeyHandler(mmi_frm_general_tab_r_arrow_key_hdlr, KEY_RIGHT_ARROW, KEY_EVENT_DOWN); 
}


static void mmi_phb_exit_generic_mark_several_tab(void)
{
    /*----------------------------------------------------------------*/
    /* Local Variables                                                */
    /*----------------------------------------------------------------*/

    /*----------------------------------------------------------------*/
    /* Code Body                                                      */
    /*----------------------------------------------------------------*/
#if defined(__MMI_PHB_QUICK_SEARCH__)
    mmi_imc_key_set_pre_key_handler(NULL);
#endif

#if defined(__MMI_MESSAGES_SEND_BY_GROUP__)
    mmi_msg_exit_generic();
#endif 
}


/*****************************************************************************
 * FUNCTION
 *  mmi_phb_entry_generic_mark_several_tab
 * DESCRIPTION
 *  tab entry function of mark several list 
 * PARAMETERS
 *  void
 * RETURNS
 *  void
 *****************************************************************************/
void mmi_phb_entry_generic_mark_several_tab(void)
{
    /*----------------------------------------------------------------*/
    /* Local Variables                                                */
    /*----------------------------------------------------------------*/
    srv_phb_filter_struct * filter;

    /*----------------------------------------------------------------*/
    /* Code Body                                                      */
    /*----------------------------------------------------------------*/
    if (!mmi_phb_check_ready(MMI_TRUE))
    {
        return;
    }

    filter = mmi_phb_list_build_filter(
                 g_mmi_phb_list_p->storage,
                 g_mmi_phb_list_p->filter,
                 &g_mmi_phb_list_p->group_filter,
                 NULL,
                 0);
    
    g_mmi_phb_list_p->contact_count = (U16) srv_phb_oplib_build_contact_list(filter, g_mmi_phb_list_p->contact_array, MMI_PHB_ENTRIES);

    mmi_phb_list_free_filter(filter);

    if (g_mmi_phb_list_p->contact_count == 0)
    {
        mmi_popup_display_simple(
            (UI_string_type)GetString(STR_ID_PHB_NO_ENTRY_TO_SELECT),
            MMI_EVENT_FAILURE,
            g_mmi_phb_list_p->sg_id,
            NULL);
    }
    else
    {
        mmi_frm_tab_struct tab_pages_info_array[2];
        U8 tab_id = 0;

        tab_pages_info_array[tab_id].screen_id = SCR_ID_PHB_MARK_SEVERAL_TAB_0;
        tab_pages_info_array[tab_id].tab_entry_func = mmi_phb_entry_generic_mark_several_tab0;
        tab_pages_info_array[tab_id].tab_icon = (U8*) GetImage(IMG_ID_PHB_TAB_LIST);
        tab_pages_info_array[tab_id++].tab_string = NULL;

    #if defined(__MMI_MESSAGES_SEND_BY_GROUP__) || defined(__MMI_UNIFIED_COMPOSER__) || defined(__MMI_MMS_STANDALONE_COMPOSER__) || defined(__MMI_JATAAYU_MMS_ADD_NUMBER_BY_GROUP__)
        tab_pages_info_array[tab_id].screen_id = SCR_ID_PHB_MARK_SEVERAL_TAB_1;
        tab_pages_info_array[tab_id].tab_entry_func = mmi_phb_entry_generic_mark_several_tab1;
        tab_pages_info_array[tab_id].tab_icon = (U8*) GetImage(IMG_ID_PHB_TAB_GROUP);
        tab_pages_info_array[tab_id++].tab_string = NULL;
    #endif /* defined(__MMI_MESSAGES_SEND_BY_GROUP__) || defined(__MMI_UNIFIED_COMPOSER__) || defined(__MMI_MMS_STANDALONE_COMPOSER__) || defined(__MMI_JATAAYU_MMS_ADD_NUMBER_BY_GROUP__) */

        mmi_frm_scrn_tab_enter(
            g_mmi_phb_list_p->sg_id,
            SCR_ID_PHB_GENERIC_MULTI_SELECT,
            mmi_phb_exit_generic_mark_several_tab,
            mmi_phb_entry_generic_mark_several_tab,
            tab_pages_info_array,
            tab_id,
            mmi_frm_scrn_tab_get_active_page_index());
    }
}
#endif /* defined(__MMI_PHB_GENERIC_MULTI_SELECT__) */

#define MMI_PHB_LIST_SINGLE_SELECT
static void mmi_phb_list_select_field_done(void)
{
    /*----------------------------------------------------------------*/
    /* Local Variables                                                */
    /*----------------------------------------------------------------*/
    U16 *name = NULL;
    U16 *select_data = NULL;
    mmi_phb_num_type_enum type;
    
    /*----------------------------------------------------------------*/
    /* Code Body                                                      */
    /*----------------------------------------------------------------*/
    name = (U16 *) srv_phb_mem_malloc(sizeof(U16) * (MMI_PHB_NAME_LENGTH + 1), SRV_PHB_MEMORY_TYPE_CTR);
    srv_phb_get_name(g_mmi_phb_list_p->store_index, name, (MMI_PHB_NAME_LENGTH + 1));

    select_data = (U16 *) srv_phb_mem_malloc(sizeof(U16) * (MMI_PHB_EMAIL_LENGTH + 1), SRV_PHB_MEMORY_TYPE_CTR);

    switch (g_mmi_phb_choose_field.number_type[g_mmi_phb_choose_field.highlight_index])
    {
        case SRV_PHB_ENTRY_FIELD_NUMBER:
            srv_phb_get_number(g_mmi_phb_list_p->store_index, select_data, MMI_PHB_NUMBER_LENGTH + 1);
            break;
            
    #if !defined(__MMI_PHB_NO_OPTIONAL_FIELD__)    
        case SRV_PHB_ENTRY_FIELD_OPT_NUM_1:
        case SRV_PHB_ENTRY_FIELD_OPT_NUM_2:
        case SRV_PHB_ENTRY_FIELD_OPT_NUM_3:
            srv_phb_get_optional_number(
                g_mmi_phb_list_p->store_index,
                g_mmi_phb_choose_field.number_type[g_mmi_phb_choose_field.highlight_index],
                select_data,
                &type,
                MMI_PHB_NUMBER_LENGTH + 1);
            break;
            
        case SRV_PHB_ENTRY_FIELD_EMAIL1:
            srv_phb_get_email_address(g_mmi_phb_list_p->store_index, select_data, MMI_PHB_EMAIL_LENGTH);
            break;
            
    #ifdef __MMI_PHB_OPTIONAL_FIELDS_2ND_EMAIL__
        case SRV_PHB_ENTRY_FIELD_EMAIL2:
            srv_phb_get_email_address2(g_mmi_phb_list_p->store_index, select_data, MMI_PHB_EMAIL_LENGTH);
            break;
    #endif
    #endif
    
    #ifdef __MMI_VOIP__
        case SRV_PHB_ENTRY_FIELD_VOIP:
            srv_phb_get_voip_number(g_mmi_phb_list_p->store_index, select_data, VOIP_URI_LEN);
            break;
    #endif
    
        default:
            break;
    }

    g_mmi_phb_list_p->evt_out = MMI_TRUE;
    
    cui_phb_list_select_contact_emit(
        g_mmi_phb_list_p->sg_id,
        EVT_ID_PHB_SELECT_CONTACT,
        name,
        select_data,
        g_mmi_phb_choose_field.number_type[g_mmi_phb_choose_field.highlight_index],
        g_mmi_phb_list_p->store_index);

    srv_phb_mem_free(name);    
    srv_phb_mem_free(select_data);
}

static void mmi_phb_list_select_done(void)
{
    /*----------------------------------------------------------------*/
    /* Local Variables                                                */
    /*----------------------------------------------------------------*/

    /*----------------------------------------------------------------*/
    /* Code Body                                                      */
    /*----------------------------------------------------------------*/    

    switch (g_mmi_phb_list_p->filter)
    {
        case SRV_PHB_ENTRY_FIELD_NAME:
        case SRV_PHB_ENTRY_FIELD_NAME | SRV_PHB_ENTRY_FIELD_ADDRESS:
        case MMI_PHB_LIST_DFAULT_FILTER:
        {
            U16 *name = NULL;
            U16 *select_data = NULL;

            name = (U16 *) srv_phb_mem_malloc(sizeof(U16) * (MMI_PHB_NAME_LENGTH + 1), SRV_PHB_MEMORY_TYPE_CTR);
            srv_phb_get_name(g_mmi_phb_list_p->store_index, name, (MMI_PHB_NAME_LENGTH + 1));
            g_mmi_phb_list_p->evt_out = MMI_TRUE;
            
            cui_phb_list_select_contact_emit(
                g_mmi_phb_list_p->sg_id,
                EVT_ID_PHB_SELECT_CONTACT,
                name,
                select_data,
                0,
                g_mmi_phb_list_p->store_index);
            
            srv_phb_mem_free(name);
            break;
        }
        
        default:
        {
            mmi_phb_entry_choose_field(
                g_mmi_phb_list_p->sg_id,
                g_mmi_phb_list_p->store_index,
                g_mmi_phb_list_p->filter,
                mmi_phb_list_select_done,
                mmi_phb_list_select_field_done,
                mmi_frm_scrn_close_active_id,
                NULL,
                MMI_FALSE,
                MMI_TRUE);
            break;
        }
    }
}


static void mmi_phb_list_select_goback(void)
{
    /*----------------------------------------------------------------*/
    /* Local Variables                                                */
    /*----------------------------------------------------------------*/

    /*----------------------------------------------------------------*/
    /* Code Body                                                      */
    /*----------------------------------------------------------------*/
    mmi_frm_scrn_close_active_id();
}


/*****************************************************************************
 * FUNCTION
 *  mmi_phb_list_select_exit
 * DESCRIPTION
 *  This function provide call back function before enter phonebook list
 * PARAMETERS
 *  
 * RETURNS
 *  void
 *****************************************************************************/
void mmi_phb_list_select_exit(void)
{
    /*----------------------------------------------------------------*/
    /* Local Variables                                                */
    /*----------------------------------------------------------------*/

    /*----------------------------------------------------------------*/
    /* Code Body                                                      */
    /*----------------------------------------------------------------*/

#if defined(__MMI_INTELLIGENT_CALL_ALERT__)
    mmi_phb_speak_name_end();
#endif

    wgui_reset_multitap();
}


/*****************************************************************************
 * FUNCTION
 *  mmi_phb_list_select_entry
 * DESCRIPTION
 *  This function provide call back function before enter phonebook list
 * PARAMETERS
 *  
 * RETURNS
 *  void
 *****************************************************************************/
void mmi_phb_list_select_entry(void)
{    
    /*----------------------------------------------------------------*/
    /* Local Variables                                                */
    /*----------------------------------------------------------------*/
    U16 contact_count;
    U8 *gui_buffer;
    srv_phb_filter_struct * filter;
    U32 handle;
    mmi_phb_refresh_struct *refresh_data;
    
    /*----------------------------------------------------------------*/
    /* Code Body                                                      */
    /*----------------------------------------------------------------*/
    if (!mmi_phb_check_ready(MMI_TRUE))
    {
        return;
    }
    
    filter = mmi_phb_list_build_filter(
                 g_mmi_phb_list_p->storage,
                 g_mmi_phb_list_p->filter,
                 &g_mmi_phb_list_p->group_filter,
                 NULL,
                 0);
    
    contact_count = (U16) srv_phb_oplib_build_contact_list(filter, g_mmi_phb_list_p->contact_array, MMI_PHB_ENTRIES);
    g_mmi_phb_list_p->contact_count = contact_count;
    
    mmi_phb_list_free_filter(filter);

    if (contact_count == 0)
    {
        mmi_popup_display_simple(
            (UI_string_type)GetString(STR_ID_PHB_NO_ENTRY_TO_SELECT),
            MMI_EVENT_FAILURE,
            g_mmi_phb_list_p->sg_id,
            NULL);

        return;
    }
    
    if (mmi_frm_scrn_enter(
            g_mmi_phb_list_p->sg_id,
            SCR_ID_PHB_GENERIC_QUICK_SEARCH_LIST,
            mmi_phb_list_select_exit,
            mmi_phb_list_select_entry,
            MMI_FRM_FULL_SCRN))
    {

        gui_buffer = mmi_frm_scrn_get_active_gui_buf();
        RegisterHighlightHandler(mmi_phb_list_highlight_handler);

        
    #ifdef __MMI_UI_HINTS_IN_MENUITEM__
        set_force_icon_on_highlight_only_in_menuitem();
    #endif

        if (gui_buffer != NULL)
        {
            if (!mmi_is_redrawing_bk_screens())
            {
                handle = mmi_phb_cntx_mgr_get_handle_by_sg_id(mmi_phb_cntx_mgr_get_current_sg_id());
                refresh_data = mmi_phb_cntx_mgr_get_refresh_data(handle);
                
                if (refresh_data != NULL && refresh_data->refresh_type != MMI_PHB_OP_NONE)
                {
                    gui_buffer = NULL;
                    g_mmi_phb_list_p->list_index = 0;
                    
                #if defined(__MMI_PHB_QUICK_SEARCH__)
                    g_mmi_phb_list_p->qsearch_input_buffer[0] = 0;
                #endif

                    refresh_data->refresh_type = MMI_PHB_OP_NONE;
                }
            }
        }
        
    #if defined(__MMI_PHB_QUICK_SEARCH__)
        RegisterCat200SearchFunction(mmi_phb_quick_search_find_entry);
        
        g_phb_quick_search_enter = MMI_PHB_QUICK_SEARCH_GENERIC;

        if (gui_buffer != NULL)
        {
            contact_count = (U16) mmi_phb_quick_search_find_entry((U8 *) g_mmi_phb_list_p->qsearch_input_buffer);
        }

        EnableCenterSoftkey(0, IMG_GLOBAL_COMMON_CSK);

        ShowCategory200Screen(
            STR_SCR_PBOOK_VIEW_CAPTION,
            IMG_SCR_PBOOK_CAPTION,
            STR_GLOBAL_OK,
            IMG_GLOBAL_OK,
            STR_GLOBAL_BACK,
            IMG_GLOBAL_BACK,
            contact_count,
            mmi_phb_list_get_item,
            mmi_phb_list_get_hint,
            g_mmi_phb_list_p->list_index,
            IMG_ID_PHB_QUICK_SEARCH_FIND,
            (U8*) g_mmi_phb_list_p->qsearch_input_buffer,
            MMI_PHB_QUICK_SEARCH_INPUT_LENGTH,
            gui_buffer);
        
        SetCategory200LeftSoftkeyFunction(mmi_phb_list_select_done, KEY_EVENT_UP);
        SetLeftSoftkeyFunction(mmi_phb_list_select_done, KEY_EVENT_UP);

        SetCenterSoftkeyFunction(mmi_phb_list_select_done, KEY_EVENT_UP);

        SetCategory200RightSoftkeyFunction(mmi_phb_list_select_goback, KEY_EVENT_UP);
    #else

        if (gui_buffer == NULL)
        {
            g_phb_highlight_alpha = 0;
        }
        
        srv_phb_oplib_build_alpha_jump_table(g_mmi_phb_list_p->contact_array, g_mmi_phb_list_p->contact_count);

        ShowCategory184Screen(
            STR_SCR_PBOOK_VIEW_CAPTION,
            IMG_SCR_PBOOK_CAPTION,
            STR_GLOBAL_OK,
            IMG_GLOBAL_OK,
            STR_GLOBAL_BACK,
            IMG_GLOBAL_BACK,
            contact_count,
            mmi_phb_list_get_item,
            mmi_phb_list_get_hint,
            g_mmi_phb_list_p->list_index,
            gui_buffer);
        
    #ifdef __MMI_QWERTY_KEYPAD_SUPPORT__
        mmi_frm_set_keypad_mode(KEYPAD_1KEY_QWERTY);
        mmi_frm_set_app_translate_key_handler(mmi_phb_list_alpha_callback);
    #else
        wgui_setup_multitap_functions(WGUI_MULTITAP_TYPE_UPPERCASE_ABC, mmi_phb_list_alpha_index, mmi_phb_list_alpha_index_input_callback);
    #endif
        
        SetLeftSoftkeyFunction(mmi_phb_list_select_done, KEY_EVENT_UP);
        SetRightSoftkeyFunction(mmi_phb_list_select_goback, KEY_EVENT_UP);

		
        ChangeCenterSoftkey(0, IMG_GLOBAL_COMMON_CSK);
        SetCenterSoftkeyFunction(mmi_phb_list_select_done, KEY_EVENT_UP);
    #endif
    }
}

/*****************************************************************************
 * FUNCTION
 *  mmi_phb_get_index_nlf
 * DESCRIPTION
 *  Gets the index of the currently highlighted item in Phonebook menu list
 *  when name_list_filter opening
 * PARAMETERS
 *  nIndex      [IN]        Highlight index position
 * RETURNS
 *  void
 *****************************************************************************/
void mmi_phb_list_highlight_handler(S32 item_index)
{
    /*----------------------------------------------------------------*/
    /* Local Variables                                                */
    /*----------------------------------------------------------------*/

    /*----------------------------------------------------------------*/
    /* Code Body                                                      */
    /*----------------------------------------------------------------*/
    /** 
     * for cancel multitap timer to avoid jump after press array key
     */
    wgui_stop_multitap();
    
    g_mmi_phb_list_p->list_index = item_index;
    g_mmi_phb_list_p->store_index = g_mmi_phb_list_p->contact_array[item_index];

    cui_phb_list_highlight_contact_emit(
        g_mmi_phb_list_p->sg_id,
        EVT_ID_PHB_LIST_CONTACT_HIGHLIGHT,
        g_mmi_phb_list_p->store_index);

#if defined(__MMI_INTELLIGENT_CALL_ALERT__)
    mmi_phb_speak_name_start();
#endif
}

#define MMI_PHB_COMMON_SCR

static void mmi_phb_entry_main_processing_timer_out_handler(void)
{
    /*----------------------------------------------------------------*/
    /* Local Variables                                                */
    /*----------------------------------------------------------------*/
    
    /*----------------------------------------------------------------*/
    /* Code Body                                                      */
    /*----------------------------------------------------------------*/
    StopTimer(PHB_NOTIFYDURATION_TIMER);
}


static void mmi_phb_exit_main_processing_scr(void)
{
    /*----------------------------------------------------------------*/
    /* Local Variables                                                */
    /*----------------------------------------------------------------*/
    
    /*----------------------------------------------------------------*/
    /* Code Body                                                      */
    /*----------------------------------------------------------------*/
    StopTimer(PHB_NOTIFYDURATION_TIMER);
}


mmi_ret mmi_phb_main_processing_scrn_proc(mmi_event_struct *param)
{
    /*----------------------------------------------------------------*/
    /* Local Variables                                                */
    /*----------------------------------------------------------------*/

    /*----------------------------------------------------------------*/
    /* Code Body                                                      */
    /*----------------------------------------------------------------*/
    switch (param->evt_id)
    {
        case EVT_ID_SCRN_DEINIT:
        {
            mmi_frm_cb_dereg_event(EVT_ID_PHB_READY, mmi_phb_main_processing_scrn_proc, NULL);

            if (param->user_data != NULL)
            {
                srv_phb_mem_free(param->user_data);
                param->user_data = NULL;
            }
            break;
        }
        
        case EVT_ID_PHB_READY:
        {
            srv_phb_startup_evt_struct *ready_evt = (srv_phb_startup_evt_struct*) param;
            
            if (ready_evt->phb_ready && mmi_frm_scrn_get_active_id() == SCR_ID_PHB_PROCESSING)
            {
                mmi_frm_node_struct *new_node_info = (mmi_frm_node_struct*) mmi_frm_scrn_get_user_data(GRP_ID_PHB_MAIN, SCR_ID_PHB_PROCESSING);
                ((FunctionPtr)(new_node_info->entry_proc))();

                mmi_frm_scrn_close(GRP_ID_PHB_MAIN, SCR_ID_PHB_PROCESSING);
            }
            else if (!ready_evt->phb_ready)
            {
                mmi_phb_cntx_mgr_controller(MMI_PHB_STATE_SAT, MMI_TRUE, NULL);
                mmi_phb_cntx_mgr_clear_history();
            }
        }
        
        default:
            break;
    }

    return MMI_RET_OK;
}


/*****************************************************************************
 * FUNCTION
 *  mmi_phb_entry_not_ready
 * DESCRIPTION
 *  Displays Phobebook not ready screen
 * PARAMETERS
 *  str_id        [IN]   String id for display     
 * RETURNS
 *  void
 *****************************************************************************/
static void mmi_phb_entry_main_processing_scr(mmi_scrn_essential_struct* scrn_data)
{
    /*----------------------------------------------------------------*/
    /* Local Variables                                                */
    /*----------------------------------------------------------------*/
    
    /*----------------------------------------------------------------*/
    /* Code Body                                                      */
    /*----------------------------------------------------------------*/
    if (srv_phb_startup_is_phb_ready())
    {
        mmi_frm_node_struct *new_node_info = (mmi_frm_node_struct*) mmi_frm_scrn_get_user_data(GRP_ID_PHB_MAIN, SCR_ID_PHB_PROCESSING);
        ((FunctionPtr)(new_node_info->entry_proc))();

        mmi_frm_scrn_close(scrn_data->group_id, SCR_ID_PHB_PROCESSING);

        return;
    }
    
    if (mmi_frm_scrn_enter(
            scrn_data->group_id,
            SCR_ID_PHB_PROCESSING,
            mmi_phb_exit_main_processing_scr,
            (FunctionPtr) mmi_phb_entry_main_processing_scr,
            MMI_FRM_FULL_SCRN))
    {
        StartTimer(
            PHB_NOTIFYDURATION_TIMER,
            mmi_get_event_based_duration(MMI_EVENT_FAILURE),
            mmi_phb_entry_main_processing_timer_out_handler);
        
        ShowCategory66Screen(
            STR_SCR_PBOOK_CAPTION,
            IMG_SCR_PBOOK_CAPTION,
            0,
            0,
            STR_GLOBAL_CANCEL,
            IMG_GLOBAL_BACK,
            (PU8) GetString(STR_GLOBAL_PLEASE_WAIT),
            IMG_GLOBAL_PROGRESS,
            NULL);

        SetRightSoftkeyFunction(mmi_frm_scrn_close_active_id, KEY_EVENT_UP);
    }
}


void mmi_phb_entry_main_processing(mmi_frm_node_struct *new_node_info)
{
    /*----------------------------------------------------------------*/
    /* Local Variables                                                */
    /*----------------------------------------------------------------*/
    
    /*----------------------------------------------------------------*/
    /* Code Body                                                      */
    /*----------------------------------------------------------------*/
    
    mmi_frm_scrn_first_enter(
        new_node_info->id,
        SCR_ID_PHB_PROCESSING,
        (FunctionPtr) mmi_phb_entry_main_processing_scr,
        new_node_info);
    
    mmi_frm_scrn_set_leave_proc(
        new_node_info->id,
        SCR_ID_PHB_PROCESSING,
        mmi_phb_main_processing_scrn_proc);

    mmi_frm_cb_reg_event(EVT_ID_PHB_READY, mmi_phb_main_processing_scrn_proc, NULL);
}


/*****************************************************************************
 * FUNCTION
 *  mmi_phb_entry_not_ready
 * DESCRIPTION
 *  Displays Phobebook not ready screen
 * PARAMETERS
 *  str_id        [IN]   String id for display     
 * RETURNS
 *  void
 *****************************************************************************/
void mmi_phb_entry_not_ready(U16 str_id)
{
    /*----------------------------------------------------------------*/
    /* Local Variables                                                */
    /*----------------------------------------------------------------*/
    mmi_id sg_id = mmi_phb_cntx_mgr_get_current_sg_id();
    
    /*----------------------------------------------------------------*/
    /* Code Body                                                      */
    /*----------------------------------------------------------------*/
    if (sg_id != GRP_ID_INVALID)
    {
        mmi_frm_scrn_enter(sg_id, SCR_PHB_DUMMY, mmi_phb_exit_not_ready, NULL, MMI_FRM_FULL_SCRN);
    }
    else
    {
        EntryNewScreen(SCR_PHB_DUMMY, mmi_phb_exit_not_ready, NULL, NULL);
    }

    StartTimer(PHB_NOTIFYDURATION_TIMER, mmi_get_event_based_duration(MMI_EVENT_FAILURE), mmi_phb_wait_and_go_back);
    
    srv_prof_play_tone(mmi_get_event_based_sound(MMI_EVENT_FAILURE), NULL);

    ShowCategory66Screen(
        STR_SCR_PBOOK_CAPTION,
        IMG_SCR_PBOOK_CAPTION,
        0,
        0,
        0,
        0,
        (PU8) GetString(str_id),
        mmi_get_event_based_image(MMI_EVENT_FAILURE),
        NULL);
}


/*****************************************************************************
 * FUNCTION
 *  mmi_phb_exit_not_ready
 * DESCRIPTION
 *  Exit function for mmi_phb_entry_not_ready.
 * PARAMETERS
 *  void
 * RETURNS
 *  void
 *****************************************************************************/
void mmi_phb_exit_not_ready(void)
{
    /*----------------------------------------------------------------*/
    /* Local Variables                                                                                          */
    /*----------------------------------------------------------------*/

    /*----------------------------------------------------------------*/
    /* Code Body                                                      */
    /*----------------------------------------------------------------*/
    StopTimer(PHB_NOTIFYDURATION_TIMER);

    srv_prof_stop_tone(mmi_get_event_based_sound(MMI_EVENT_FAILURE));
}


/*****************************************************************************
 * FUNCTION
 *  mmi_phb_wait_and_go_back
 * DESCRIPTION
 *  Goes back to history after timer expires
 * PARAMETERS
 *  void
 * RETURNS
 *  void
 *****************************************************************************/
void mmi_phb_wait_and_go_back(void)
{
    /*----------------------------------------------------------------*/
    /* Local Variables                                                */
    /*----------------------------------------------------------------*/

    /*----------------------------------------------------------------*/
    /* Code Body                                                      */
    /*----------------------------------------------------------------*/
    StopTimer(PHB_NOTIFYDURATION_TIMER);
    
    srv_prof_stop_tone(mmi_get_event_based_sound(MMI_EVENT_FAILURE));

    mmi_frm_scrn_close_active_id();
}


/*****************************************************************************
 * FUNCTION
 *  mmi_phb_show_in_progress
 * DESCRIPTION
 *  To display work-in-progress status
 * PARAMETERS
 *  msg         [IN]        
 *  msgIcon     [IN]        
 * RETURNS
 *  void
 *****************************************************************************/
void mmi_phb_show_in_progress(mmi_id sg_id, U16 msg)
{
    /*----------------------------------------------------------------*/
    /* Local Variables                                                */
    /*----------------------------------------------------------------*/

    /*----------------------------------------------------------------*/
    /* Code Body                                                      */
    /*----------------------------------------------------------------*/
    g_mmi_phb_message = msg;
    mmi_frm_scrn_first_enter(sg_id, SCR_IN_PROGRESS_PHB, (FuncPtr)mmi_phb_entry_in_progress, NULL);
}


/*****************************************************************************
 * FUNCTION
 *  mmi_phb_entry_in_progress
 * DESCRIPTION
 *  Draws the in-progress screen
 * PARAMETERS
 *  void
 * RETURNS
 *  void
 *****************************************************************************/
void mmi_phb_entry_in_progress(mmi_scrn_essential_struct* scrn_data)
{
    /*----------------------------------------------------------------*/
    /* Local Variables                                                */
    /*----------------------------------------------------------------*/

    /*----------------------------------------------------------------*/
    /* Code Body                                                      */
    /*----------------------------------------------------------------*/
    if (!mmi_frm_scrn_enter(
            scrn_data->group_id,
            scrn_data->scrn_id,
            NULL,
            (FuncPtr)mmi_phb_entry_in_progress,
            MMI_FRM_UNKNOW_SCRN))
    {
        return;
    }
#ifdef __MMI_MAINLCD_240X320__
    /* passing 0xffff for Title string and Title icon for the disbling the status bar and title display. */
    ShowCategory8Screen(
        0xffff,
        0xffff,
        0,
        0,
        0,
        0,
        g_mmi_phb_message,
        mmi_get_event_based_image(MMI_EVENT_PROGRESS),
        NULL);
#else /* __MMI_MAINLCD_240X320__ */ 
    ShowCategory8Screen(
        STR_SCR_PBOOK_CAPTION,
        IMG_SCR_PBOOK_CAPTION,
        0,
        0,
        0,
        0,
        g_mmi_phb_message,
        mmi_get_event_based_image(MMI_EVENT_PROGRESS),
        NULL);
#endif /* __MMI_MAINLCD_240X320__ */ 

    ClearInputEventHandler(MMI_DEVICE_ALL);
    ClearKeyHandler(KEY_END, KEY_EVENT_UP);
    ClearKeyHandler(KEY_END, KEY_EVENT_DOWN);
    ClearKeyHandler(KEY_END, KEY_LONG_PRESS);
    ClearKeyHandler(KEY_END, KEY_REPEAT);
}


static mmi_ret mmi_phb_mass_processing_set_scrn_proc(mmi_event_struct *param)
{
    /*----------------------------------------------------------------*/
    /* Local Variables                                                */
    /*----------------------------------------------------------------*/

    /*----------------------------------------------------------------*/
    /* Code Body                                                      */
    /*----------------------------------------------------------------*/
    switch (param->evt_id)
    {
        case EVT_ID_SCRN_DEINIT:
            break;
            
        case EVT_ID_SCRN_GOBACK_IN_END_KEY:
        case EVT_ID_SCRN_DELETE_REQ_IN_END_KEY:
            mmi_phb_multi_op_cancel();
            break;
            
        case EVT_ID_SCRN_DELETE_REQ:
            if (g_phb_cntx_mgr.processing & (srv_ucm_query_call_count(SRV_UCM_CALL_STATE_ALL, SRV_UCM_CALL_TYPE_NO_CSD, NULL) == 0))  /* if phonebook still copying or deleting, do not deleted this screen */
            {
                return -1;
            }        
            break;
             
        default:
            break;
    }

    return MMI_RET_OK;
}


/*****************************************************************************
 * FUNCTION
 *  mmi_phb_show_mass_processing
 * DESCRIPTION
 *  To display work-in-progress status for mass operation
 * PARAMETERS
 *  msg         [IN]        
 *  msgIcon     [IN]        
 * RETURNS
 *  void
 *****************************************************************************/
void mmi_phb_show_mass_processing(mmi_id sg_id, U16 msg, U16 total_count)
{
    /*----------------------------------------------------------------*/
    /* Local Variables                                                */
    /*----------------------------------------------------------------*/

    /*----------------------------------------------------------------*/
    /* Code Body                                                      */
    /*----------------------------------------------------------------*/
    g_mmi_phb_message = msg;
    g_mmi_phb_max_op_finish_count = 0;
    g_mmi_phb_max_op_total_count = total_count;
    mmi_frm_scrn_first_enter(sg_id, SCR_COPY_ALL_PROGRESS, (FuncPtr)mmi_phb_entry_mass_processing, NULL);

    mmi_frm_scrn_set_leave_proc(
        sg_id,
        SCR_COPY_ALL_PROGRESS,
        mmi_phb_mass_processing_set_scrn_proc);
}


/*****************************************************************************
 * FUNCTION
 *  mmi_phb_entry_mass_processing
 * DESCRIPTION
 *  Draws the in-progress screen for mass operation. (This screen has abort function.)
 * PARAMETERS
 *  void
 * RETURNS
 *  void
 *****************************************************************************/
void mmi_phb_entry_mass_processing(mmi_scrn_essential_struct* scrn_data)
{
    /*----------------------------------------------------------------*/
    /* Local Variables                                                */
    /*----------------------------------------------------------------*/
    WCHAR string[14];
    U16 percentage;
    
    /*----------------------------------------------------------------*/
    /* Code Body                                                      */
    /*----------------------------------------------------------------*/    
    if (mmi_frm_scrn_enter(
            scrn_data->group_id,
            scrn_data->scrn_id,
            NULL,
            (FuncPtr)mmi_phb_entry_mass_processing,
            MMI_FRM_UNKNOW_SCRN))
    {
        kal_wsprintf(string, "%d/%d", g_mmi_phb_max_op_finish_count, g_mmi_phb_max_op_total_count);
        percentage = (g_mmi_phb_max_op_finish_count * 100) / g_mmi_phb_max_op_total_count;
        ShowCategory402Screen(
                (U8*) GetString(STR_SCR_PBOOK_CAPTION),
                IMG_SCR_PBOOK_CAPTION,
                0,
                0,
                STR_GLOBAL_CANCEL,
                IMG_COPY_ALL_ABORT,
                (U8*)GetString(g_mmi_phb_message),
                percentage,
                (U8*)string);

        /* If this screen is deleted, call back function. */

        if (srv_ucm_query_call_count(SRV_UCM_CALL_STATE_ALL, SRV_UCM_CALL_TYPE_NO_CSD, NULL) == 0)
        {
            ClearInputEventHandler(MMI_DEVICE_KEY);
        }

        SetRightSoftkeyFunction(mmi_phb_mass_processing_abort, KEY_EVENT_UP);
    }
}


/*****************************************************************************
 * FUNCTION
 *  mmi_phb_mass_processing_scr_del_callback
 * DESCRIPTION
 *  Call back function when the screen is deleted
 * PARAMETERS
 *  p       [?]     
 * RETURNS
 *  void
 *****************************************************************************/
U8 mmi_phb_mass_processing_scr_del_callback(void *p)
{
    /*----------------------------------------------------------------*/
    /* Local Variables                                                */
    /*----------------------------------------------------------------*/

    /*----------------------------------------------------------------*/
    /* Code Body                                                      */
    /*----------------------------------------------------------------*/
    if (g_phb_cntx_mgr.processing & (srv_ucm_query_call_count(SRV_UCM_CALL_STATE_ALL, SRV_UCM_CALL_TYPE_NO_CSD, NULL) == 0))  /* if phonebook still copying or deleting, do not deleted this screen */
    {
        return MMI_TRUE;
    }
    else
    {
        return MMI_FALSE;
    }
}


/*****************************************************************************
 * FUNCTION
 *  mmi_phb_update_mass_processing
 * DESCRIPTION
 *  delete all interfce
 * PARAMETERS
 *  void
 * RETURNS
 *  void
 *****************************************************************************/
mmi_ret mmi_phb_update_mass_processing(mmi_event_struct* param)
{
    /*----------------------------------------------------------------*/
    /* Local Variables                                                */
    /*----------------------------------------------------------------*/
    
    /*----------------------------------------------------------------*/
    /* Code Body                                                      */
    /*----------------------------------------------------------------*/    
    if (mmi_frm_scrn_get_active_id() == SCR_COPY_ALL_PROGRESS)
    {
        U16 percentage;
        WCHAR string[14];
        srv_phb_multi_op_status_evt_struct* evt = (srv_phb_multi_op_status_evt_struct*)param;
		g_mmi_phb_max_op_finish_count = evt->finish_count;
        percentage = (evt->finish_count * 100) / evt->total_count;
        kal_wsprintf(string, "%d/%d", evt->finish_count, evt->total_count);
        UpdateCategory402Value(percentage, (U8*)string);
    }
    return MMI_RET_OK;
}


#ifdef __MMI_PHB_TWO_LINE_MENUITEM_DISPLAY__
static S32 phb_numbers[MMI_PHB_MAX_NUMBER_COUNT];
static S32 phb_total_number_present;
static U8 current_highligted_item = 0;
MMI_BOOL g_phb_two_line_number_refresh = MMI_FALSE;
U16 g_mmi_phb_list_img_path[SRV_FMGR_PATH_MAX_LEN + 1];

#ifdef __MMI_PHB_DEFAULT_NUMBER__
static U8 default_highlighted_item = 0;
#endif
/*****************************************************************************
 * FUNCTION
 *  mmi_phb_inline_display_style
 * DESCRIPTION
 *  Returns the display style for the phonebook list(will return INLINE SELECT style always)
 * PARAMETERS
 *  item_index      [IN]        Actual index of the menuitem in the list
 * RETURNS
 *  U8 display style     TWO_LINE_MENUITEM_STYLE_DISPLAY_HORIZONTAL_SELECT
 *****************************************************************************/
U8 mmi_phb_inline_display_style(S32 item_index)
{
    /*----------------------------------------------------------------*/
    /* Local Variables                                                */
    /*----------------------------------------------------------------*/

    /*----------------------------------------------------------------*/
    /* Code Body                                                      */
    /*----------------------------------------------------------------*/

    return TWO_LINE_MENUITEM_STYLE_DISPLAY_HORIZONTAL_SELECT;
}


/*****************************************************************************
 * FUNCTION
 *  mmi_phb_inline_default_value
 * DESCRIPTION
 *  Returns the default inline item to be shown with the entry(Only phone
 *  numbers to be considered)
 * PARAMETERS
 *  item_index      [IN]        Actual index of the menuitem in the list
 * RETURNS
 *  S32
 *****************************************************************************/
S32 mmi_phb_inline_default_value(S32 item_index)
{
    /*----------------------------------------------------------------*/
    /* Local Variables                                                */
    /*----------------------------------------------------------------*/

    /*----------------------------------------------------------------*/
    /* Code Body                                                      */
    /*----------------------------------------------------------------*/
    if (g_phb_two_line_number_refresh)
    {
        g_phb_two_line_number_refresh = MMI_FALSE;
        
    #ifdef __MMI_PHB_DEFAULT_NUMBER__
        current_highligted_item = default_highlighted_item;
    #else
        current_highligted_item = 0;
    #endif
    }
    
    return (current_highligted_item < phb_total_number_present) ? current_highligted_item : (phb_total_number_present - 1);
}


/*****************************************************************************
 * FUNCTION
 *  mmi_phb_two_line_send_key_handler
 * DESCRIPTION
 *  This is the send key handler in case of two line menu item in phone book
 * PARAMETERS
 *  void
 *  Input: NONE(?)
 * RETURNS
 *  void
 *****************************************************************************/
void mmi_phb_two_line_send_key_handler(void)
{
    /*----------------------------------------------------------------*/
    /* Local Variables                                                */
    /*----------------------------------------------------------------*/
    U16 store_index;
    U8 number_to_dial = 0;
    U16 dialing_number[MMI_PHB_NUMBER_LENGTH + 1 + 1];
    mmi_phb_op_action_cntx_struct op_cntx;

    /*----------------------------------------------------------------*/
    /* Code Body                                                      */
    /*----------------------------------------------------------------*/
    store_index = g_mmi_phb_list_p->store_index;

    while (phb_numbers[number_to_dial] != current_highligted_item + 1 && number_to_dial <= MMI_PHB_MAX_NUMBER_COUNT)
    {
        ++number_to_dial;
    }

    mmi_phb_op_cntx_init(&op_cntx);
    op_cntx.store_index = store_index;
    op_cntx.op_action = MMI_PHB_OP_CALL;

#ifdef __MMI_PHB_DEFAULT_NUMBER__
    if (phb_total_number_present == 0)
    {
        if (!mmi_phb_og_start_browser(store_index, mmi_phb_cntx_mgr_get_current_sg_id()))
        {
            mmi_phb_op_start(&op_cntx, g_mmi_phb_list_p->sg_id);
        }
        return;
    }
#endif

    switch (number_to_dial)
    {
        case MMI_PHB_MOBILE_NUMBER:
            srv_phb_get_number(store_index, dialing_number, (U16)(MMI_PHB_NUMBER_LENGTH + 1));
            op_cntx.data = dialing_number;
            op_cntx.data_type = SRV_PHB_ENTRY_FIELD_NUMBER;
            break;
        
        case MMI_PHB_OPTION_NUMBER_1:
        case MMI_PHB_OPTION_NUMBER_2:
        case MMI_PHB_OPTION_NUMBER_3:
            op_cntx.data = dialing_number;
            op_cntx.data_type = SRV_PHB_ENTRY_FIELD_OPT_NUM_1 << (number_to_dial - 1);
            srv_phb_get_optional_number(
                store_index,
                op_cntx.data_type,
                dialing_number,
                NULL,
                MMI_PHB_NUMBER_PLUS_LENGTH);
            break;
            
        default:
            if (store_index >= MMI_PHB_PHONE_ENTRIES)    /* Entry in SIM */
            {
                srv_phb_get_number(store_index, dialing_number, (U16)(MMI_PHB_NUMBER_LENGTH + 1));
                op_cntx.data = dialing_number;
                op_cntx.data_type = SRV_PHB_ENTRY_FIELD_NUMBER;
            }
            break;
    }

    mmi_phb_op_start(&op_cntx, g_mmi_phb_list_p->sg_id);
}


/*****************************************************************************
 * FUNCTION
 *  mmi_phb_inline_select_data
 * DESCRIPTION
 *  This function sets the relevant data for the phonebook entry
 * PARAMETERS
 *  item_index              [IN]        Menuitem index
 *  inline_item_index       [IN]        Inline item index
 *  str_buff                [IN]        Inline Item String to be shown
 *  img_buff_p              [?]         Image to be shown with the inline item
 *  thumbnail               [?]         Thumbnail picture to be shown with the inline item
 * RETURNS
 *  S32
 *****************************************************************************/
pBOOL mmi_phb_inline_select_data(
        S32 item_index,
        S32 inline_item_index,
        UI_string_type str_buff,
        PU8 *img_buff_p,
        wgui_thumbnail_image_union *thumbnail)
{
    /*----------------------------------------------------------------*/
    /* Local Variables                                                */
    /*----------------------------------------------------------------*/
    U16 store_index = 0;
    S16 next_phb_number_index = 0;
    pBOOL val = FALSE;
    U16 img_id;
    mmi_phb_num_type_enum type;

    /*----------------------------------------------------------------*/
    /* Code Body                                                      */
    /*----------------------------------------------------------------*/
    store_index = g_mmi_phb_list_p->contact_array[item_index];

    if (!phb_total_number_present)
    {
        next_phb_number_index = -1;
    }
    else
    {
        current_highligted_item = inline_item_index;
        while (phb_numbers[next_phb_number_index] != (inline_item_index + 1) &&
               next_phb_number_index <= MMI_PHB_MAX_NUMBER_COUNT)
        {
            next_phb_number_index++;
        }
    }    

    switch (next_phb_number_index)
    {
        case MMI_PHB_MOBILE_NUMBER:
            srv_phb_get_number(store_index, (U16*) str_buff, (U16)(MMI_PHB_NUMBER_LENGTH + 1));
            *img_buff_p = get_image((U16) (IMG_MOBILE_NUMBER));
            val = TRUE;
            break;
            
        case MMI_PHB_OPTION_NUMBER_1:
        case MMI_PHB_OPTION_NUMBER_2:
        case MMI_PHB_OPTION_NUMBER_3:
            srv_phb_get_optional_number(
                store_index,
                SRV_PHB_ENTRY_FIELD_OPT_NUM_1 << (next_phb_number_index - 1),
                (U16*) str_buff,
                &type,
                MMI_PHB_NUMBER_PLUS_LENGTH);
            *img_buff_p = get_image(mmi_phb_get_img_by_number_type(type));
            val = TRUE;
            break;
        default:
            *img_buff_p = get_image((U16) UI_NULL_IMAGE);
            mmi_asc_to_ucs2((S8*) str_buff, (PS8) "");
            val = TRUE;
            break;
    }

    if (store_index < srv_phb_get_total_contact(PHB_STORAGE_NVRAM)) /* in NVRAM */
    {
        U16 res_type;
        srv_phb_get_image(store_index, &img_id, g_mmi_phb_list_img_path, &res_type);

        if (res_type & SRV_PHB_RES_TYPE_IMAGE_FILE)
        {
        #if defined(__MMI_FILE_MANAGER__) && !defined(__MMI_DISPLAY_CHAR_HIDE_MENU_FROM_FILE__)
            if (mmi_phb_res_check_valid(img_id, g_mmi_phb_list_img_path))
            {
                thumbnail->path = (S8*)g_mmi_phb_list_img_path;
            }
            else
        #endif
            {
                thumbnail->id = IMG_PHB_DEFAULT;
            }
        }
        else if (img_id)
        {
            thumbnail->id = img_id & 0x3fff;
        }
        else
        {
            thumbnail->id = IMG_PHB_DEFAULT;
        }
    }
    else
    {
        thumbnail->id = IMG_ID_PHB_LIST_ICON1;
    }
    return val;
}


/*****************************************************************************
 * FUNCTION
 *  mmi_phb_inline_select_done
 * DESCRIPTION
 *  Sets highlighted item to zero always
 * PARAMETERS
 *  menuitem_index      [IN]        Actual index of the menuitem in the list
 *  selected_index      [IN]        Inline item currently selected
 *****************************************************************************/
void mmi_phb_inline_select_done(S32 menuitem_index, S32 selected_index)
{
    /*----------------------------------------------------------------*/
    /* Local Variables                                                */
    /*----------------------------------------------------------------*/

    /*----------------------------------------------------------------*/
    /* Code Body                                                      */
    /*----------------------------------------------------------------*/
#ifdef __MMI_PHB_DEFAULT_NUMBER__
    current_highligted_item = default_highlighted_item;
#else
    current_highligted_item = 0;
#endif
}


/*****************************************************************************
 * FUNCTION
 *  mmi_phb_inline_menuitem_properties
 * DESCRIPTION
 *  This function is used to get the properties of the selected menu item
 * PARAMETERS
 *  index                           [IN]        Menu item index
 *  current_menuitem_properties     [?]         Structure to be filled for menuitem properties
 * RETURNS
 *  U8(?)
 *****************************************************************************/
void mmi_phb_inline_menuitem_properties(int index, wgui_two_line_menuitem_struct *current_menuitem_properties)
{
    /*----------------------------------------------------------------*/
    /* Local Variables                                                */
    /*----------------------------------------------------------------*/
    U16 store_index = 0;
    S16 number_count = 0;
    S16 entry_count = 0;
    U16 img_id;
    U16 res_type;
    U32 field;    
#ifdef __MMI_PHB_DEFAULT_NUMBER__
    U8 default_nubmer_id;
#endif
    /*----------------------------------------------------------------*/
    /* Code Body                                                      */
    /*----------------------------------------------------------------*/
    store_index = g_mmi_phb_list_p->contact_array[index];
    
    current_menuitem_properties->image_flags = UI_TWO_LINE_MENUITEM_NO_THUMBNAIL;
    current_menuitem_properties->image_flags |= UI_TWO_LINE_MENUITEM_LEFT_ALIGN_THUMBNAIL;

    if (store_index < srv_phb_get_total_contact(PHB_STORAGE_NVRAM)) /* in NVRAM */
    {
        mmi_phb_build_image_list();
        srv_phb_get_image(store_index, &img_id, g_mmi_phb_list_img_path, &res_type);

        if (res_type & SRV_PHB_RES_TYPE_IMAGE_FILE)
        {
        #if defined(__MMI_FILE_MANAGER__) && !defined(__MMI_DISPLAY_CHAR_HIDE_MENU_FROM_FILE__)
            if (mmi_phb_res_check_valid(img_id, g_mmi_phb_list_img_path))
            {
                current_menuitem_properties->image_flags |= UI_TWO_LINE_MENUITEM_THUMBNAIL_IS_FILE;
            }
            else
        #endif
            {
                current_menuitem_properties->image_flags |= UI_TWO_LINE_MENUITEM_THUMBNAIL_IS_ID;
            }
        }
        else if (img_id)
        {
            current_menuitem_properties->image_flags |= UI_TWO_LINE_MENUITEM_THUMBNAIL_IS_ID;
        }
        else
        {
            current_menuitem_properties->image_flags |= UI_TWO_LINE_MENUITEM_THUMBNAIL_IS_ID;
        }
    }
    else
    {
        current_menuitem_properties->image_flags |= UI_TWO_LINE_MENUITEM_THUMBNAIL_IS_ID;
    }

    memset(phb_numbers, 0, sizeof(phb_numbers));

    
    srv_phb_get_field(store_index, &field);

    /* entry_count signifies the array entry,number_count corresponds to the index of the phone number */
    if (field & SRV_PHB_ENTRY_FIELD_NUMBER)
    {
        number_count++;
        phb_numbers[entry_count] = number_count;

    }

    if (srv_phb_get_storage(store_index) == PHB_STORAGE_NVRAM)
    {
        U8 number_order[MMI_PHB_OPT_NUM_COUNT];
        S32 i;
        srv_phb_get_optional_number_order(store_index, number_order);
        for (i = 0; i < MMI_PHB_OPT_NUM_COUNT; i++)
        {
            if (field & number_order[i])
            {
                number_count++;
                switch (number_order[i])
                {
                    case SRV_PHB_ENTRY_FIELD_OPT_NUM_1:
                        phb_numbers[MMI_PHB_OPTION_NUMBER_1] = number_count;
                        break;
                        
                    case SRV_PHB_ENTRY_FIELD_OPT_NUM_2:
                        phb_numbers[MMI_PHB_OPTION_NUMBER_2] = number_count;
                        break;
                        
                    case SRV_PHB_ENTRY_FIELD_OPT_NUM_3:
                        phb_numbers[MMI_PHB_OPTION_NUMBER_3] = number_count;
                        break;
                        
                    default:
                        break;
                }
            }
            else
            {
                break;
            }
        }
    }

#ifdef __MMI_PHB_DEFAULT_NUMBER__
    srv_phb_get_default_number_id(store_index, &default_nubmer_id);

    switch (default_nubmer_id)
    {
        case SRV_PHB_ENTRY_FIELD_OPT_NUM_1:   //home
             if (phb_numbers[MMI_PHB_OPTION_NUMBER_1])
             {
                 default_highlighted_item = phb_numbers[MMI_PHB_OPTION_NUMBER_1] - 1;
             }
            else
            {
                default_highlighted_item = 0;
            }
             break;

        case SRV_PHB_ENTRY_FIELD_OPT_NUM_2:  //office
            if (phb_numbers[MMI_PHB_OPTION_NUMBER_2])
                {
                    default_highlighted_item = phb_numbers[MMI_PHB_OPTION_NUMBER_2] - 1;
                }
                else
                {
                    default_highlighted_item = 0;
                }
                break;

        case SRV_PHB_ENTRY_FIELD_OPT_NUM_3:      //fax
            if (phb_numbers[MMI_PHB_OPTION_NUMBER_3])
            {
             default_highlighted_item = phb_numbers[MMI_PHB_OPTION_NUMBER_3] - 1;
            }
            else
            {
            default_highlighted_item = 0;
            }
            break;

        case SRV_PHB_ENTRY_FIELD_NUMBER:    //mobile
        case 0xff:                          //default value
        case 0xfe:                          //has been canceled
        default:
            default_highlighted_item = 0;
            break;
    }
#endif

    phb_total_number_present = number_count;
    current_menuitem_properties->num_of_items = phb_total_number_present;
    current_menuitem_properties->defualt_value_callback = mmi_phb_inline_default_value;
    current_menuitem_properties->complete_callback = mmi_phb_inline_select_done;
    current_menuitem_properties->two_line_data_callback.get_data_for_horizontal_select = mmi_phb_inline_select_data;
}
#endif /* __MMI_PHB_TWO_LINE_MENUITEM_DISPLAY__ */ 


/*****************************************************************************
 * FUNCTION
 *  mmi_phb_exit_list
 * DESCRIPTION
 *  This function is for existing entering phonebook entry List
 * PARAMETERS
 *  void
 * RETURNS
 *  void
 *****************************************************************************/
void mmi_phb_exit_list(void)
{
    /*----------------------------------------------------------------*/
    /* Local Variables                                                */
    /*----------------------------------------------------------------*/

    /*----------------------------------------------------------------*/
    /* Code Body                                                      */
    /*----------------------------------------------------------------*/
#if defined(__MMI_INTELLIGENT_CALL_ALERT__)
    mmi_phb_speak_name_end();
#endif /* defined(__MMI_INTELLIGENT_CALL_ALERT__) */ 

    wgui_reset_multitap();

    StopTimer(KEYPAD_LOCK_TIMER);
    
#if defined(__MMI_VRSD_DIAL__)
    StopTimer(VRSD_DIAL_PLAYBACK_TIMER);
#endif
}

/*****************************************************************************
 * FUNCTION
 *  mmi_phb_entry_list
 * DESCRIPTION
 *  This function is for entering phonebook entry List
 * PARAMETERS
 *  EntryCount          [IN]        
 *  STR_TITLE           [IN]        
 *  IMG_TITLE           [IN]        
 *  STR_LSK             [IN]        
 *  IMG_LSK             [IN]        
 *  HighlightPtr        [IN]        
 *  LSKPtr              [IN]        
 *  SendKeyPtr          [IN]        
 *  ItemPtr             [IN]        
 *  HintPtr             [IN]        
 *  EntryPtr            [IN]        
 *  alpha_index         [IN]        
 *  right_arrow         [IN]        
 * RETURNS
 *  void
 *****************************************************************************/
void mmi_phb_entry_list(
        mmi_id sg_id,
        U16 EntryCount,
        U16 STR_TITLE,
        U16 IMG_TITLE,
        U16 STR_LSK,
        U16 IMG_LSK,
        U16 STR_CSK,
        U16 IMG_CSK,
        void (*HighlightPtr) (S32),
        FunctionPtr LSKPtr,
        FunctionPtr CSKPtr,
        FunctionPtr SendKeyPtr,
        GetItemPtr ItemPtr,
        GetHintPtr HintPtr,
        FunctionPtr EntryPtr,
        BOOL alpha_index)
{
    /*----------------------------------------------------------------*/
    /* Local Variables                                                */
    /*----------------------------------------------------------------*/
    U8 *gui_buffer;
    U32 handle;
    mmi_phb_refresh_struct *refresh_data;

    /*----------------------------------------------------------------*/
    /* Code Body                                                      */
    /*----------------------------------------------------------------*/
     if (!mmi_phb_check_ready(MMI_TRUE))
    {
        return;   
    }

    if (EntryCount == 0)
    {
        mmi_popup_display_simple(
            (UI_string_type)GetString(STR_NO_ENTRIES_MESSAGE),
            MMI_EVENT_FAILURE,
            sg_id,
            NULL);

        mmi_frm_scrn_close(sg_id, SCR_PBOOK_LIST);
        return;
    }

    if (!mmi_frm_scrn_enter(
            sg_id,
            SCR_PBOOK_LIST,
            mmi_phb_exit_list,
            EntryPtr,
            MMI_FRM_FULL_SCRN))
    {
        return;
    }

    gui_buffer = mmi_frm_scrn_get_active_gui_buf();
    RegisterHighlightHandler(HighlightPtr);

    /* refresh prefer storage */
    if (g_mmi_phb_list_p->storage != mmi_phb_get_preferred_storage() ||
        g_mmi_phb_list_p->display_type != srv_phb_get_name_display_type())
    {
        g_mmi_phb_list_p->storage = (U8) mmi_phb_get_preferred_storage();
        g_mmi_phb_list_p->display_type = (U8) srv_phb_get_name_display_type();
        gui_buffer = NULL;

        g_mmi_phb_list_p->list_index = 0;
    }

    if (gui_buffer == NULL)
    {
        if (alpha_index)
        {
            g_phb_highlight_alpha = 0;
        }
    }
    else
    {
        if (!mmi_is_redrawing_bk_screens())
        {
            handle = mmi_phb_cntx_mgr_get_handle_by_sg_id(mmi_phb_cntx_mgr_get_current_sg_id());
            refresh_data = mmi_phb_cntx_mgr_get_refresh_data(handle);
        
            if (refresh_data != NULL && refresh_data->refresh_type != MMI_PHB_OP_NONE)
            {
                gui_buffer = NULL;
        
                if (EntryCount == 0)
                {
                    g_mmi_phb_list_p->list_index = 0;
                }
                else
                {
                    g_mmi_phb_list_p->list_index = mmi_phb_calc_list_index(
                                                    refresh_data,
                                                    MMI_PHB_LIST_TYPE_SINGLE_SELECT,
                                                    g_mmi_phb_list_p->list_index,
                                                    g_mmi_phb_list_p->contact_array,
                                                    NULL,
                                                    g_mmi_phb_list_p->contact_count);
                }
                
                refresh_data->refresh_type = MMI_PHB_OP_NONE;
            }
        }
    }

    if (alpha_index)
    {
        srv_phb_oplib_build_alpha_jump_table(g_mmi_phb_list_p->contact_array, g_mmi_phb_list_p->contact_count);
    }
#ifdef __MMI_PHB_TWO_LINE_MENUITEM_DISPLAY__
    if (gui_buffer == NULL)
    {
        current_highligted_item = 0;
    }
#endif /* __MMI_PHB_TWO_LINE_MENUITEM_DISPLAY__ */ 

    if (CSKPtr)
    {    
        EnableCenterSoftkey(STR_CSK, IMG_CSK);
    }    

#ifdef __MMI_PHB_TWO_LINE_MENUITEM_DISPLAY__
    ShowCategory273Screen(
        STR_TITLE,
        IMG_TITLE,
        STR_LSK,
        IMG_LSK,
        STR_GLOBAL_BACK,
        IMG_GLOBAL_BACK,
        EntryCount,
        ItemPtr,
        mmi_phb_inline_display_style,
        mmi_phb_inline_menuitem_properties,
        g_mmi_phb_list_p->list_index,
        gui_buffer);
#ifdef __MMI_TOUCH_SCREEN__
    wgui_register_list_item_selected_callback_all(UI_dummy_function);
#endif 
#else
    ShowCategory184Screen(
        STR_TITLE,
        IMG_TITLE,
        STR_LSK,
        IMG_LSK,
        STR_GLOBAL_BACK,
        IMG_GLOBAL_BACK,
        EntryCount,
        ItemPtr,
        HintPtr,
        g_mmi_phb_list_p->list_index,
        gui_buffer);
#endif

    /* register multi-tap function for fast jump, for full list only */
    if (alpha_index)
    {
    #ifdef __MMI_QWERTY_KEYPAD_SUPPORT__
        mmi_frm_set_keypad_mode(KEYPAD_1KEY_QWERTY);
        mmi_frm_set_app_translate_key_handler(mmi_phb_list_alpha_callback);
    #else
        wgui_setup_multitap_functions(WGUI_MULTITAP_TYPE_UPPERCASE_ABC, mmi_phb_list_alpha_index, mmi_phb_list_alpha_index_input_callback);
    #endif
    }

    SetLeftSoftkeyFunction(LSKPtr, KEY_EVENT_UP);
    SetKeyHandler(SendKeyPtr, KEY_SEND, KEY_EVENT_UP);

    if (CSKPtr)
    {
        SetCenterSoftkeyFunction(CSKPtr, KEY_EVENT_UP);
    }

    SetRightSoftkeyFunction(mmi_frm_scrn_close_active_id, KEY_EVENT_UP);

#if defined(__IP_NUMBER__) && defined(__MMI_IP_KEY__)   /* For IP Dial Key */
/* under construction !*/
#endif /* defined(__IP_NUMBER__) && defined(__MMI_IP_KEY__) */ 
}

/*****************************************************************************
 * FUNCTION
 *  mmi_phb_entry_list_ext
 * DESCRIPTION
 *  This function is for entering phonebook entry List
 * PARAMETERS
 *  entry_count         [IN]        
 *  str_title           [IN]        
 *  img_title           [IN]        
 *  str_lsk             [IN]        
 *  img_lsk             [IN]
 *  scr_id              [IN]
 *  highlight_ptr       [IN]        
 *  lsk_ptr             [IN]
 *  csk_ptr             [IN]
 *  send_key_ptr        [IN]
 *  ip_key_ptr          [IN]
 *  item_ptr            [IN]        
 *  hint_ptr            [IN]        
 *  entry_ptr           [IN]
 *  exit_ptr            [IN]
 *  alpha_index         [IN]            
 * RETURNS
 *  void
 *****************************************************************************/
void mmi_phb_entry_list_ext(
        mmi_id sg_id,
        U16 entry_count,
        U16 str_title,
        U16 img_title,
        U16 str_lsk,
        U16 img_lsk,
        U16 scr_id,
        U16 img_csk,
        HighlightPtr highlight_ptr,
        FunctionPtr lsk_ptr,
        FunctionPtr csk_ptr,
        FunctionPtr send_key_ptr,
        FunctionPtr ip_key_ptr,
        GetItemPtr item_ptr,
        GetHintPtr hint_ptr,
        FunctionPtr entry_ptr,
        FunctionPtr exit_ptr,
        MMI_BOOL alpha_index)
{
    /*----------------------------------------------------------------*/
    /* Local Variables                                                */
    /*----------------------------------------------------------------*/
    U8 *gui_buffer;
    U32 handle;
    mmi_phb_refresh_struct *refresh_data;

    /*----------------------------------------------------------------*/
    /* Code Body                                                      */
    /*----------------------------------------------------------------*/
    if (!mmi_phb_check_ready(MMI_TRUE))
    {
        return;
    }

    if (entry_count == 0)
    {
        mmi_popup_display_simple(
            (UI_string_type)GetString(STR_ID_PHB_NO_ENTRY_TO_SELECT),
            MMI_EVENT_FAILURE,
            sg_id,
            NULL);
        return;
    }

    if (!mmi_frm_scrn_enter(
            sg_id,
            scr_id,
            exit_ptr,
            entry_ptr,
            MMI_FRM_FULL_SCRN))
    {
        return;
    }
    gui_buffer = mmi_frm_scrn_get_active_gui_buf();
    RegisterHighlightHandler(highlight_ptr);
    
    if (gui_buffer == NULL)
    {
        if (alpha_index)
        {
            g_phb_highlight_alpha = 0;
        }
    }
    else
    {
        if (!mmi_is_redrawing_bk_screens())
        {
            handle = mmi_phb_cntx_mgr_get_handle_by_sg_id(mmi_phb_cntx_mgr_get_current_sg_id());
            refresh_data = mmi_phb_cntx_mgr_get_refresh_data(handle);
        
            if (refresh_data != NULL && refresh_data->refresh_type != MMI_PHB_OP_NONE)
            {
                gui_buffer = NULL;
        
                if (entry_count == 0)
                {
                    g_mmi_phb_list_p->list_index = 0;
                }
                else
                {
                    g_mmi_phb_list_p->list_index = mmi_phb_calc_list_index(
                                                    refresh_data,
                                                    MMI_PHB_LIST_TYPE_SINGLE_SELECT,
                                                    g_mmi_phb_list_p->list_index,
                                                    g_mmi_phb_list_p->contact_array,
                                                    NULL,
                                                    g_mmi_phb_list_p->contact_count);
                }
                
                refresh_data->refresh_type = MMI_PHB_OP_NONE;
            }
        }
    }
    
    if (alpha_index)
    {
        srv_phb_oplib_build_alpha_jump_table(g_mmi_phb_list_p->contact_array, g_mmi_phb_list_p->contact_count);
    }
    
    if (csk_ptr)
    {
        EnableCenterSoftkey(0, img_csk);
    }

    ShowCategory184Screen(
        str_title,
        img_title,
        str_lsk,
        img_lsk,
        STR_GLOBAL_BACK,
        IMG_GLOBAL_BACK,
        entry_count,
        item_ptr,
        hint_ptr,
        g_mmi_phb_list_p->list_index,
        gui_buffer);
    

    /* register multi-tap function for fast jump, for full list only */
    if (alpha_index)
    {
    #ifdef __MMI_QWERTY_KEYPAD_SUPPORT__
        mmi_frm_set_keypad_mode(KEYPAD_1KEY_QWERTY);
        mmi_frm_set_app_translate_key_handler(mmi_phb_list_alpha_callback);
    #else
        wgui_setup_multitap_functions(WGUI_MULTITAP_TYPE_UPPERCASE_ABC, mmi_phb_list_alpha_index, mmi_phb_list_alpha_index_input_callback);
    #endif
    }

    SetLeftSoftkeyFunction(lsk_ptr, KEY_EVENT_UP);
    SetRightSoftkeyFunction(mmi_frm_scrn_close_active_id, KEY_EVENT_UP);

    if (csk_ptr)
    {   
        SetCenterSoftkeyFunction(csk_ptr, KEY_EVENT_UP);
    }

    SetKeyHandler(send_key_ptr, KEY_SEND, KEY_EVENT_UP);
#if defined(__IP_NUMBER__) && defined(__MMI_IP_KEY__)   /* For IP Dial Key */
/* under construction !*/
#endif
}


/*****************************************************************************
 * FUNCTION
 *  mmi_phb_field_list_highlight_handler
 * DESCRIPTION
 *  Gets the index of the currently highlighted item in Phonebook menu list.
 * PARAMETERS
 *  nIndex      [IN]        Highlight index position
 * RETURNS
 *  void
 *****************************************************************************/
void mmi_phb_field_list_highlight_handler(S32 field_index)
{
    /*----------------------------------------------------------------*/
    /* Local Variables                                                */
    /*----------------------------------------------------------------*/

    /*----------------------------------------------------------------*/
    /* Code Body                                                      */
    /*----------------------------------------------------------------*/
    /* for cancel multitap timer to avoid jump after press array key */
    wgui_stop_multitap();
    g_mmi_phb_choose_field.highlight_index = (U8) field_index;
}


mmi_ret mmi_phb_choose_number_scrn_proc(mmi_event_struct *param)
{
    /*----------------------------------------------------------------*/
    /* Local Variables                                                */
    /*----------------------------------------------------------------*/

    /*----------------------------------------------------------------*/
    /* Code Body                                                      */
    /*----------------------------------------------------------------*/
    switch (param->evt_id)
    {
        case EVT_ID_SCRN_DEINIT:
            if (param->user_data != NULL)
            {
                srv_phb_mem_free(param->user_data);
                param->user_data = NULL;
            }
            mmi_frm_group_close(GRP_ID_CHOOSE_FIELD);
            break;

        default:
            break;
    }

    return MMI_RET_OK;
}


/*****************************************************************************
 * FUNCTION
 *  mmi_phb_entry_choose_field_ex
 * DESCRIPTION
 *  Allows the user to choose one number to some action  if the entry has more than one number
 * PARAMETERS
 *  sg_id                  [IN]
 *  store_index         [IN]        
 *  EntryFunc           [IN]        
 *  RSKFunc             [IN]        
 *  ActionFunc          [IN]        
 *  empty_str_id        [IN]        
 *  dial_list           [IN]        
 * RETURNS
 *  void
 *****************************************************************************/
void mmi_phb_entry_choose_field_ex(
        mmi_id sg_id,
        WCHAR *name,
        const U8* select_type,
        U32 field_mask,
        FunctionPtr entry_func,
        FunctionPtr lsk_func,
        FunctionPtr rsk_func)
{
    /*----------------------------------------------------------------*/
    /* Local Variables                                                */
    /*----------------------------------------------------------------*/
    U8 field_type = 0, i = 0, index = 0;
    U8 *gui_buffer;
    U16 img_list[MMI_PHB_FIELD_TOTAL];
    U16 title_str[MMI_PHB_NAME_LENGTH + 1];
    U32 field;
    
    /*----------------------------------------------------------------*/
    /* Code Body                                                      */
    /*----------------------------------------------------------------*/
    while (select_type[index] != MMI_PHB_FIELD_TOTAL)
    {
        field_type = select_type[index];
        field = mmi_phb_get_field_mask_by_field_type(field_type);
        if (field  && ((field & field_mask) != field))
        {
            g_mmi_phb_choose_field.number_to_dial[i] = (U16 *)GetString(mmi_phb_get_str_by_field_type(field_type, PHB_STORAGE_NVRAM));
            g_mmi_phb_choose_field.number_type[i] = (U32)field_type;
            img_list[i++] = mmi_phb_get_img_by_field_type(field_type);
        }
        index++;
    }

    if (!mmi_frm_scrn_enter(
            sg_id, 
            SCR_CHOOSE_NUMBER,
            NULL,
            entry_func,
            MMI_FRM_FULL_SCRN))
    {
        return;
    }

    gui_buffer = mmi_frm_scrn_get_active_gui_buf();
    RegisterHighlightHandler(mmi_phb_field_list_highlight_handler);

    if (gui_buffer == NULL)
    {
        g_mmi_phb_choose_field.highlight_index = 0;
    }

    if (name[0])
    {
        mmi_wcsncpy(title_str, name, MMI_PHB_NAME_LENGTH);
    }
    else
    {
        mmi_wcsncpy(title_str, (WCHAR*) GetString(STR_ID_PHB_UNNAMED), MMI_PHB_NAME_LENGTH);
    }
    
    EnableCenterSoftkey(0, IMG_GLOBAL_COMMON_CSK);

    ShowCategory353Screen(
        (U8*)title_str,
        IMG_SCR_PBOOK_CAPTION,
        STR_GLOBAL_OK,
        IMG_GLOBAL_OK,
        STR_GLOBAL_BACK,
        IMG_GLOBAL_BACK,
        i,
        (U8**)g_mmi_phb_choose_field.number_to_dial,
        img_list,
        NULL,
        0,
        0,
        gui_buffer);

    SetLeftSoftkeyFunction(lsk_func, KEY_EVENT_UP);
    SetCenterSoftkeyFunction(lsk_func, KEY_EVENT_UP);
    SetRightSoftkeyFunction(rsk_func, KEY_EVENT_UP);
}


/*****************************************************************************
 * FUNCTION
 *  mmi_phb_entry_choose_field
 * DESCRIPTION
 *  Allows the user to choose one number to some action  if the entry has more than one number
 * PARAMETERS
 *  sg_id                  [IN]
 *  store_index         [IN]        
 *  EntryFunc           [IN]        
 *  RSKFunc             [IN]        
 *  ActionFunc          [IN]        
 *  empty_str_id        [IN]        
 *  dial_list           [IN]        
 * RETURNS
 *  void
 *****************************************************************************/
void mmi_phb_entry_choose_field(
        mmi_id sg_id,
        U16 store_index,
        U32 field_type,
        FunctionPtr entry_func,
        FunctionPtr lsk_func,
        FunctionPtr rsk_func,
        FunctionPtr send_key_func,
        MMI_BOOL show_if_empty,
        MMI_BOOL start_primitive)
{
    /*----------------------------------------------------------------*/
    /* Local Variables                                                */
    /*----------------------------------------------------------------*/
    U8 i = 0;
    U8 *gui_buffer;
    U16 number_type_image_list[7];
    U8  *title_string;
    U32 field;
    srv_phb_contact_info_struct* contact_info;
    MMI_BOOL new_num = MMI_FALSE;
    U32 new_filed;
    
    /*----------------------------------------------------------------*/
    /* Code Body                                                      */
    /*----------------------------------------------------------------*/
    srv_phb_get_field(store_index, &field);
    contact_info = mmi_phb_get_contact_build_buffer(&g_mmi_phb_field_data);
    contact_info->field_mask = field_type;
    srv_phb_oplib_get_contact_info(store_index, contact_info);
    mmi_phb_get_contact_free_buffer(contact_info);
    if (field_type & SRV_PHB_ENTRY_FIELD_NUMBER)
    {
        if (field & SRV_PHB_ENTRY_FIELD_NUMBER)
        {
            g_mmi_phb_choose_field.number_to_dial[i] = g_mmi_phb_field_data.number;
            g_mmi_phb_choose_field.number_type[i] = SRV_PHB_ENTRY_FIELD_NUMBER;
            number_type_image_list[i++] = IMG_MOBILE_NUMBER;
        }
        else if (show_if_empty)
        {
            new_num = MMI_TRUE;
            new_filed = 0;
        }
    }
    
    if (field_type & SRV_PHB_ENTRY_FIELD_OPTIONAL)
    {
        if (srv_phb_get_storage(store_index) == PHB_STORAGE_NVRAM)
        {
        #if !defined(__MMI_PHB_NO_OPTIONAL_FIELD__)
            S32 j, temp_index;
            for (j = 0; j < MMI_PHB_OPT_NUM_COUNT; j++)
            {
                temp_index = (U32)(g_mmi_phb_field_data.opt_order[j]);
                if (field_type & temp_index)
                {
                    if (field & temp_index)
                    {
                        g_mmi_phb_choose_field.number_to_dial[i] = 
                            g_mmi_phb_field_data.opt_num[mmi_phb_get_field_type_by_field_mask(temp_index) - MMI_PHB_FIELD_OPT_NUM_1].number;
                        g_mmi_phb_choose_field.number_type[i] = temp_index;
                        number_type_image_list[i++] = mmi_phb_get_img_by_number_type(g_mmi_phb_field_data.opt_num[mmi_phb_get_field_type_by_field_mask(temp_index) - MMI_PHB_FIELD_OPT_NUM_1].type);
                    }
                    else if (show_if_empty)
                    {
                        new_num = MMI_TRUE;
                        new_filed = SRV_PHB_ENTRY_FIELD_ALL;
                    }
                }
            }

            if (field_type & SRV_PHB_ENTRY_FIELD_EMAIL)
            {
                if (field & SRV_PHB_ENTRY_FIELD_EMAIL1)
                {
                    g_mmi_phb_choose_field.number_to_dial[i] = g_mmi_phb_field_data.emailAddress;
                    g_mmi_phb_choose_field.number_type[i] = SRV_PHB_ENTRY_FIELD_EMAIL1;
                    number_type_image_list[i++] = IMG_EMAIL_ADDRESS;
                }
            #if defined(__MMI_PHB_OPTIONAL_FIELDS_2ND_EMAIL__)
                if (field & SRV_PHB_ENTRY_FIELD_EMAIL2)
                {
                    g_mmi_phb_choose_field.number_to_dial[i] = g_mmi_phb_field_data.emailAddress2;
                    g_mmi_phb_choose_field.number_type[i] = SRV_PHB_ENTRY_FIELD_EMAIL2;
                    number_type_image_list[i++] = IMG_EMAIL_ADDRESS;
                }
            #endif /* __MMI_PHB_OPTIONAL_FIELDS_2ND_EMAIL__ */
            }
        #endif /* !defined(__MMI_PHB_NO_OPTIONAL_FIELD__) */ 
        }
    }
    
    if (new_num)
    {
        g_mmi_phb_choose_field.number_to_dial[i] = (U16 *)GetString(STR_ID_PHB_ADD_MORE_NUMBER);
        g_mmi_phb_choose_field.number_type[i] = new_filed;
        number_type_image_list[i++] = IMG_ID_PHB_NEW_NUMBER;
    }
    
#ifdef __MMI_VOIP__
    if ((store_index < srv_phb_get_total_contact(PHB_STORAGE_NVRAM) 
        && field_type & SRV_PHB_ENTRY_FIELD_VOIP))
    {
        if (field & SRV_PHB_ENTRY_FIELD_VOIP)
        {
            g_mmi_phb_choose_field.number_to_dial[i] = g_mmi_phb_field_data.voip;
            g_mmi_phb_choose_field.number_type[i] = SRV_PHB_ENTRY_FIELD_VOIP;
            number_type_image_list[i++] = IMG_ID_PHB_VOIP;
        }
    }
#endif /* __MMI_VOIP__ */

    if (!i)
    {
        MMI_BOOL ret;
        /* leave no number to dial to popup by ucm for unified behavior, so aribitrary send a zero length num to ucm */
        g_mmi_phb_choose_field.highlight_index = 0;

        memset(g_mmi_phb_field_data.number, 0x00, ENCODING_LENGTH);
        g_mmi_phb_choose_field.number_to_dial[0] = g_mmi_phb_field_data.number;
        ret = mmi_frm_scrn_enter(
            sg_id, 
            SCR_CHOOSE_NUMBER,
            NULL,
            NULL,
            0);
        if (ret == MMI_TRUE)
        {
            ShowCategoryDummyScreen();
        }
        if (start_primitive)
        {
            StartTimer(PHB_CHOOSE_FIELD_TIMER, 0, lsk_func);
        }
        else
        {
            lsk_func();
        }
    }
    else if (i == 1 && !new_num)
    {
        MMI_BOOL ret;
        g_mmi_phb_choose_field.highlight_index = 0;
        ret = mmi_frm_scrn_enter(
            sg_id, 
            SCR_CHOOSE_NUMBER,
            NULL,
            NULL,
            0);
        if (ret == MMI_TRUE)
        {
            ShowCategoryDummyScreen();
        }
        if (start_primitive)
        {
            StartTimer(PHB_CHOOSE_FIELD_TIMER, 0, lsk_func);
        }
        else
        {
            lsk_func();
        }
    }
    else
    {
        if (!mmi_frm_scrn_enter(
                sg_id, 
                SCR_CHOOSE_NUMBER,
                NULL,
                (FunctionPtr)entry_func,
                MMI_FRM_FULL_SCRN))
        {
            return;
        }

        gui_buffer = mmi_frm_scrn_get_active_gui_buf();
        RegisterHighlightHandler(mmi_phb_field_list_highlight_handler);
        if (gui_buffer == NULL)
        {
            g_mmi_phb_choose_field.highlight_index = 0;
        }
        if (field & SRV_PHB_ENTRY_FIELD_NAME)
        {
            srv_phb_get_name(store_index, g_mmi_phb_field_data.name, (U16)(MMI_PHB_NAME_LENGTH + 1));
            title_string = (U8 *) g_mmi_phb_field_data.name;
        }
        else
        {
            title_string = (U8*)GetString(STR_ID_PHB_UNNAMED);
        }

        EnableCenterSoftkey(0, IMG_GLOBAL_COMMON_CSK);

        ShowCategory353Screen(
            title_string,
            IMG_SCR_PBOOK_CAPTION,
            STR_GLOBAL_OK,
            IMG_GLOBAL_OK,
            STR_GLOBAL_BACK,
            IMG_GLOBAL_BACK,
            i,
            (U8**)g_mmi_phb_choose_field.number_to_dial,
            number_type_image_list,
            NULL,
            0,
            0,
            gui_buffer);

        SetLeftSoftkeyFunction(lsk_func, KEY_EVENT_UP);
        SetKeyHandler(send_key_func, KEY_SEND, KEY_EVENT_DOWN);
        SetCenterSoftkeyFunction(lsk_func, KEY_EVENT_UP);
        SetRightSoftkeyFunction(rsk_func, KEY_EVENT_UP);
    }
}

#define MMI_PHB_LIST_UTIL
#ifdef __MMI_QWERTY_KEYPAD_SUPPORT__
/*****************************************************************************
 * FUNCTION
 *  mmi_phb_list_alpha_callback
 * DESCRIPTION
 *  jump to the item by input char
 * PARAMETERS
 *  key_code            [IN]     
 *  key_type            [IN]
 *  ucs2_value          [IN]
 *  key_flag              [IN]
 * RETURNS
 *  MMI_BOOL
 *****************************************************************************/
MMI_BOOL mmi_phb_list_alpha_callback(S16 key_code, S16 key_type, U16 ucs2_value, U32 key_flag)
{
    /*----------------------------------------------------------------*/
    /* Local Variables                                                */
    /*----------------------------------------------------------------*/

    /*----------------------------------------------------------------*/
    /* Code Body                                                      */
    /*----------------------------------------------------------------*/
    if ((key_code >= KEY_A && key_code <= KEY_Z) && (key_type == KEY_EVENT_DOWN))
    {        
        g_phb_highlight_alpha = srv_phb_oplib_get_alpha_index((U16) key_code);

        mmi_phb_list_alpha_index_input_callback();

	return MMI_TRUE;
    }
    
    return MMI_FALSE;
}


/*****************************************************************************
 * FUNCTION
 *  mmi_phb_list_alpha_callback_ext
 * DESCRIPTION
 *  jump to the item by input char
 * PARAMETERS
 *  key_code            [IN]     
 *  key_type            [IN]
 *  ucs2_value          [IN]
 *  key_flag              [IN]
 * RETURNS
 *  MMI_BOOL
 *****************************************************************************/
MMI_BOOL mmi_phb_list_alpha_callback_ext(S16 key_code, S16 key_type, U16 ucs2_value, U32 key_flag)
{
    /*----------------------------------------------------------------*/
    /* Local Variables                                                */
    /*----------------------------------------------------------------*/

    /*----------------------------------------------------------------*/
    /* Code Body                                                      */
    /*----------------------------------------------------------------*/
    if ((key_code >= KEY_A && key_code <= KEY_Z) && (key_type == KEY_EVENT_DOWN))
    {        
        g_phb_highlight_alpha = srv_phb_oplib_get_alpha_index((U16) key_code);

        mmi_phb_list_alpha_index_input_callback_ext();

        return MMI_TRUE;
    }
    
    return MMI_FALSE;
}

#endif


/*****************************************************************************
 * FUNCTION
 *  mmi_phb_list_alpha_index
 * DESCRIPTION
 *  This function calculates the index of the entry to be highlighted, if the user jumps to some
 *  entry using multi-tap on PHB list screen.
 * PARAMETERS
 *  input       [IN]        Input character
 * RETURNS
 *  void
 *****************************************************************************/
void mmi_phb_list_alpha_index(U16 input)
{
    /*----------------------------------------------------------------*/
    /* Local Variables                                                */
    /*----------------------------------------------------------------*/

    /*----------------------------------------------------------------*/
    /* Code Body                                                      */
    /*----------------------------------------------------------------*/
    if (input >= 'A' && input <= 'Z')
    {
        g_phb_highlight_alpha = srv_phb_oplib_get_alpha_index((U16) input);
    }
}


/*****************************************************************************
 * FUNCTION
 *  mmi_phb_list_alpha_index_input_callback_ext
 * DESCRIPTION
 *  Jumps to the hilited entry
 * PARAMETERS
 *  void
 * RETURNS
 *  void
 *****************************************************************************/
void mmi_phb_list_alpha_index_input_callback_ext(void)
{
    /*----------------------------------------------------------------*/
    /* Local Variables                                                */
    /*----------------------------------------------------------------*/

    /*----------------------------------------------------------------*/
    /* Code Body                                                      */
    /*----------------------------------------------------------------*/
    /* 1 for Add new contact */
    dynamic_list_goto_item((S32)(g_phb_highlight_alpha + 1));  /* Use Dynamic List */
}


/*****************************************************************************
 * FUNCTION
 *  mmi_phb_list_alpha_index_input_callback
 * DESCRIPTION
 *  Jumps to the hilited entry
 * PARAMETERS
 *  void
 * RETURNS
 *  void
 *****************************************************************************/
void mmi_phb_list_alpha_index_input_callback(void)
{
#if defined(__MMI_FILE_MANAGER__)
    /*----------------------------------------------------------------*/
    /* Local Variables                                                */
    /*----------------------------------------------------------------*/

    /*----------------------------------------------------------------*/
    /* Code Body                                                      */
    /*----------------------------------------------------------------*/
    if (UI_device_height == 220 && UI_device_width == 176)
    {
        Cat212ShortCutHdlr(g_phb_highlight_alpha);  /* For image list fast jump */
    }
    else
#endif /* defined(__MMI_FILE_MANAGER__) */ 
        dynamic_list_goto_item(g_phb_highlight_alpha);  /* Use Dynamic List */
}

srv_phb_filter_struct *mmi_phb_list_build_filter(
                           U8 storage,
                           U32 field_filter,
                           srv_phb_group_filter_struct* group_filter,
                           U16* key_word,
                           U16 input_mode)
{
    /*----------------------------------------------------------------*/
    /* Local Variables                                                */
    /*----------------------------------------------------------------*/
    srv_phb_filter_struct *filter;
    srv_phb_qsearch_filter_struct *search_filter = NULL;

    /*----------------------------------------------------------------*/
    /* Code Body                                                      */
    /*----------------------------------------------------------------*/
    filter = (srv_phb_filter_struct *) srv_phb_mem_malloc(sizeof(srv_phb_filter_struct), SRV_PHB_MEMORY_TYPE_CTR);

    filter->storage= storage;
    filter->field_filter = field_filter;

    if (group_filter != NULL && group_filter->group_mask != 0xffff)
    {
        filter->group_filter = group_filter;
    }
    else
    {
        filter->group_filter = NULL;
    }

    if (key_word)
    {
        search_filter = (srv_phb_qsearch_filter_struct *) srv_phb_mem_malloc(sizeof(srv_phb_qsearch_filter_struct), SRV_PHB_MEMORY_TYPE_CTR);

        search_filter->key_len = mmi_wcslen(key_word);
        search_filter->key_word = key_word;
        search_filter->input_mode = input_mode;
    }

    filter->qsearch_filter = search_filter;

    return filter;
}

void mmi_phb_list_free_filter(srv_phb_filter_struct *filter)
{
    /*----------------------------------------------------------------*/
    /* Local Variables                                                */
    /*----------------------------------------------------------------*/

    /*----------------------------------------------------------------*/
    /* Code Body                                                      */
    /*----------------------------------------------------------------*/
    if (filter)
    {
        if (filter->qsearch_filter)
        {
            srv_phb_mem_free(filter->qsearch_filter);
            filter->qsearch_filter = NULL;
        }
        
        srv_phb_mem_free(filter);
    }
}


pBOOL mmi_phb_list_get_item(S32 item_index, UI_string_type str_buff, PU8 *img_buff_p, U8 str_img_mask)
{
    /*----------------------------------------------------------------*/
    /* Local Variables                                                */
    /*----------------------------------------------------------------*/
    
    /*----------------------------------------------------------------*/
    /* Code Body                                                      */
    /*----------------------------------------------------------------*/
    srv_phb_get_name(g_mmi_phb_list_p->contact_array[item_index], str_buff, MAX_SUBMENU_CHARACTERS);

#if defined(__MMI_DSM_NEW__) && defined( __HC_CALL_NEW__)//for 11B
	{
		extern int HcCall_hist_populate_call_list(char * city_name,int city_name_size,char *city_number);

		U16 number_ucs_array[MAX_SUBMENU_CHARACTERS]={0};
		S8 number_asc_array[MAX_SUBMENU_CHARACTERS]={0};
		S8 city_array[MAX_SUBMENU_CHARACTERS];
		memset(city_array,0,MAX_SUBMENU_CHARACTERS);
		srv_phb_get_number(g_mmi_phb_list_p->contact_array[item_index], number_ucs_array, MAX_SUBMENU_CHARACTERS);
		mmi_ucs2_to_asc((S8*)number_asc_array, (S8*)number_ucs_array);
		HcCall_hist_populate_call_list(city_array,MAX_SUBMENU_CHARACTERS>>1,number_asc_array);

		if((mmi_ucs2strlen(city_array)+mmi_ucs2strlen((S8*)str_buff))<=MAX_SUBMENU_CHARACTERS)
		{
			mmi_ucs2ncpy((S8*)(str_buff+mmi_ucs2strlen((S8*)str_buff)),city_array,mmi_ucs2strlen(city_array));
		}
	}
#endif
    if (str_buff[0] == 0)
    {
        mmi_ucs2ncpy((S8*) str_buff, GetString(STR_ID_PHB_UNNAMED), MAX_SUBMENU_CHARACTERS);
    }

    mmi_phb_contact_get_item_image(g_mmi_phb_list_p->contact_array[item_index], img_buff_p);

    return TRUE;
}

S32 mmi_phb_list_get_hint(S32 item_index, UI_string_type *hint_array)
{
    /*----------------------------------------------------------------*/
    /* Local Variables                                                */
    /*----------------------------------------------------------------*/
    U16 store_index;

    /*----------------------------------------------------------------*/
    /* Code Body                                                      */
    /*----------------------------------------------------------------*/
    if (item_index > g_mmi_phb_list_p->contact_count - 1)
    {
        return 0;
    }
    
    store_index = g_mmi_phb_list_p->contact_array[item_index];
    
    if (g_mmi_phb_list_p->filter & SRV_PHB_ENTRY_FIELD_NUMBER)
    {
        srv_phb_get_number(store_index, (U16*) hint_array[0], MAX_SUBMENU_CHARACTERS);

        if (hint_array[0][0] != 0)
        {
            return 1;
        }
    }
#if !defined(__MMI_PHB_NO_OPTIONAL_FIELD__)
    if (g_mmi_phb_list_p->filter & SRV_PHB_ENTRY_FIELD_EMAIL)
    {
        if (srv_phb_get_storage(store_index) != PHB_STORAGE_NVRAM)
        {
            return 0;
        }

        if (srv_phb_get_email_address(store_index, (U16*) hint_array[0], MAX_SUBMENU_CHARACTERS))
        {
            if (hint_array[0][0] != 0)
            {
                return 1;
            }
        }
#if defined(__MMI_PHB_OPTIONAL_FIELDS_2ND_EMAIL__)
        if (srv_phb_get_email_address2(store_index, (U16*) hint_array[0], MAX_SUBMENU_CHARACTERS))
        {
            if (hint_array[0][0] != 0)
            {
                return 1;
            }
        }
#endif /* __MMI_PHB_OPTIONAL_FIELDS_2ND_EMAIL__ */
    }
#endif /* !defined(__MMI_PHB_NO_OPTIONAL_FIELD__) */
#if defined(__MMI_PHB_INFO_FIELD__)
    if (g_mmi_phb_list_p->filter & SRV_PHB_ENTRY_FIELD_ADDRESS)
    {
        if (srv_phb_get_storage(store_index) != PHB_STORAGE_NVRAM)
        {
            return 0;
        }

        if (srv_phb_get_address(
                store_index,
                NULL,
                NULL,
                (U16*) hint_array[0],
                NULL,
                NULL,
                NULL,
                NULL))
        {
            if (hint_array[0][0] != 0)
            {
                return 1;
            }
        }
    }
#endif /* defined(__MMI_PHB_INFO_FIELD__) */
    /**
     * If not select any field type, default type is number
     */
    if (srv_phb_get_number(store_index, (U16*) hint_array[0], MAX_SUBMENU_CHARACTERS))
    {
        if (hint_array[0][0] != 0)
        {
            return 1;
        }
    }

    return 0;
}

S32 mmi_phb_list_get_hint_ext(S32 item_index, UI_string_type *hint_array)
{
    /*----------------------------------------------------------------*/
    /* Local Variables                                                */
    /*----------------------------------------------------------------*/
    U16 store_index;

    /*----------------------------------------------------------------*/
    /* Code Body                                                      */
    /*----------------------------------------------------------------*/
    if (item_index > g_mmi_phb_list_p->contact_count - 1)
    {
        return 0;
    }
    
    store_index = g_mmi_phb_list_p->contact_array[item_index];
    
#ifdef __MMI_PHB_DEFAULT_NUMBER__
    srv_phb_get_default_number(store_index, (U16*)hint_array[0], NULL, (U16)(MMI_PHB_NUMBER_LENGTH + 1));
    if (hint_array[0][0] == 0)
    {
        srv_phb_get_number(store_index, (U16*)hint_array[0], MAX_SUBMENU_CHARACTERS);
    }
#else /* __MMI_PHB_DEFAULT_NUMBER__ */
    srv_phb_get_number(store_index, (U16*)hint_array[0], MAX_SUBMENU_CHARACTERS);
#endif /* __MMI_PHB_DEFAULT_NUMBER__ */

    if (hint_array[0][0] == 0)
    {
        return 0;
    }

    return 1;   /* One hint data only, can be more hints. */
}

